Crates.io | truncate_string_at_whitespace |
lib.rs | truncate_string_at_whitespace |
version | 1.0.3 |
source | src |
created_at | 2021-05-07 01:19:33.972393 |
updated_at | 2024-04-02 00:06:01.344275 |
description | Truncate a &str at the closest whitespace to a specified length with unicode safety |
homepage | https://git.sr.ht/~toddself/truncate_string_at_whitespace |
repository | https://git.sr.ht/~toddself/truncate_string_at_whitespace |
max_upload_size | |
id | 394055 |
size | 5,277 |
Truncate a string at a certain length, using the closest whitespace character.
Add the following to your Cargo.toml
truncate_string_at_whitespace = "1.0.2"
Then
use truncate_string_at_whitespace::truncate_text;
fn main () {
let s = "This is a string that I want to truncate";
let st = truncate_text(s, 12);
assert_eq!(st, "This is a");
let st2 = truncate_text(s, 16);
assert_eq!(st2, "This is a string");
}
© 2021 Todd Kennedy, Apache-2.0