mgeisler / textwrap

An efficient and powerful Rust library for word wrapping text.
MIT License
446 stars 44 forks source link

Create an `abbreviate` function which can shorten text to a specific width #513

Open mgeisler opened 1 year ago

mgeisler commented 1 year ago

We have all the infrastructure (and dependencies) needed to add a small abbreviate or truncate function which will shorten text to a specific width.

The most forward way is wrong in Rust: returning &s[..width] is prone to panicking since you can end up slicing into a Unicode character.