Packages / rupm

rs-text-truncate 0.1.0

Truncate text with an ellipsis by characters, display width or words, plus middle truncation for paths

Install

cargo add rs-text-truncate --registry rupm

In Ruststudio: Packages, search for rs-text-truncate, Install.

Owner: Rust Studio. Licence: MIT OR Apache-2.0. Total downloads: 0. Published 2026-11-23.

Versions

README

# rs-text-truncate

Truncate text with an ellipsis by characters, display width or words, plus middle truncation for paths.

## Install

`rupm add rs-text-truncate` (or `cargo add rs-text-truncate --registry rupm`).

## Usage

```rust
let s = rs_text_truncate::chars("Hello, world", 8); // "Hello..."
let p = rs_text_truncate::middle("/usr/local/share/app/file.txt", 20);
```

## API overview

- `chars(text, max)`: limit by character count, ellipsis included.
- `width(text, max)`: limit by approximate display columns (wide CJK counts 2, combining marks 0).
- `words(text, max)`: limit by length without cutting a word.
- `middle(text, max)`: keeps both ends, good for paths.
- `with_ellipsis` variants take a custom ellipsis string.