boundstr
A string type for Rust whose length is guaranteed to be within bounds.
Example
use BString;
Truncation never splits a character. It cuts at the last character boundary that still fits, so the result may be shorter than the maximum.
use ;
// '🐈' is 4 bytes in UTF-8, but only 3 are left.
let s = from_str_truncated;
assert_eq!;
assert_eq!;
// '🐈' is 2 code units in UTF-16, but only 1 is left.
let s = from_str_truncated;
assert_eq!;
// The cat is either in the box or not. Never half of it.
let s = from_str_truncated;
assert_eq!;
License
This project is licensed under the MIT License.