1 unstable release

0.1.0 May 17, 2021

#3 in #detached

47 downloads per month
Used in 5 crates (3 directly)

Apache-2.0 OR MIT

14KB
360 lines

detached-str

Safely borrow strings without a lifetime.

Documentation

License

Licensed under either of

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.

No runtime deps