Crate bos[−][src]
Expand description
This crate provides flexible Borrowed, Owned or Shared smart pointers.
They are like std’s Cow
but with additonal Arc
and Rc
variants.
Abos
or Bos
Abos
implements Send
and Sync
but does not have a Rc
variant.
Bos
does not implement Send
or Sync
but does have a Rc
variant.
Examples
use bos::Abos; fn maybe_replace_with_reply(string: &mut Abos<str>) { if string.contains("Hello") { *string.to_mut() = String::from("Hello to you, too."); } } let mut string = Abos::Borrowed("Hello bos!"); maybe_replace_with_reply(&mut string); assert_eq!(&string, "Hello to you, too.")
use bos::Abos; struct Header<'a> { name: bos::AStr<'a>, // AStr<'a> is a type alias for Abos<'a, str> bytes: Abos<'a, [u8]>, } fn add_global_header(header: Header<'static>) { // ... }
struct Logger { // Use the 'static lifetime, if you don't want // to introduce generic lifetimes to your struct. name: bos::AStr<'static>, }
AStr
and Str
types
Abos
and Bos
are often used with str
or similar types.
Feel free to have a look at our handy type aliases below.