1 unstable release
0.1.0 | May 17, 2021 |
---|
#27 in #safely
54 downloads per month
Used in 5 crates
(3 directly)
14KB
360 lines
detached-str
Safely borrow strings without a lifetime.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
lib.rs
:
A crate for borrowing strings without a lifetime.
Example
use detached_str::{Str, StrSlice};
let string: Str = "Hello, world!".into();
let slice: StrSlice = string.get(7..);
assert_eq!(slice.to_str(&string), "world!");
A StrSlice
is "detached", i.e. the string content can only be accessed
when you have a reference to the owned string. The owned string is immutable
to ensure that string slices remain valid.