Enum bos::Bos [−][src]
#[non_exhaustive]
pub enum Bos<'b, B: ?Sized, O = B, S: ?Sized = O> where
B: 'static + ?Sized,
O: 'static,
S: 'static + ?Sized, {
Borrowed(&'b B),
Owned(O),
BorrowedArc(&'b Arc<S>),
Arc(Arc<S>),
BorrowedRc(&'b Rc<S>),
Rc(Rc<S>),
}
Expand description
Borrowed, Owned or Shared smart pointer.
The enum is currently marked as non_exhaustive
and has 'static
bounds
so we may later add a Static(&'static B)
variant or something similar.
Variants (Non-exhaustive)
This enum is marked as non-exhaustive
Tuple Fields of Borrowed
0: &'b B
Tuple Fields of BorrowedArc
0: &'b Arc<S>
Tuple Fields of Arc
0: Arc<S>
Tuple Fields of BorrowedRc
0: &'b Rc<S>
Tuple Fields of Rc
0: Rc<S>
Implementations
Extracts the owned data.
Clones the data if it is not already owned.
Examples
Calling into_owned
on a Bos::Borrowed
clones the inner data.
use bos::{Bos, BosStr};
let bos: BosStr = Bos::Borrowed("Hello!");
let owned: String = bos.into_owned();
assert_eq!(owned, "Hello!");
Calling into_owned
on a Bos::Owned
doesn’t clone anything.
use bos::{Bos, BosStr};
let bos: BosStr = Bos::Owned("Hello!".to_owned());
let owned: String = bos.into_owned();
assert_eq!(owned, "Hello!");
Calling into_owned
on a Bos::Arc
or Bos::Rc
only clones the inner data
if the reference count is greater than one.
use bos::{Bos, BosStr};
let bos: BosStr = Bos::Rc("Hello!".to_owned().into());
let owned: String = bos.into_owned();
assert_eq!(owned, "Hello!");
Acquires a mutable reference to the owned form of the data.
Clones the data if it is not already owned.
Examples
Calling to_mut
on a Bos::Borrowed
clones the inner data.
use bos::{Bos, BosStr};
let mut hello: BosStr = Bos::Borrowed("Hello");
hello.to_mut().push_str(", Barbara!");
assert_eq!(hello, "Hello, Barbara!");
Calling to_mut
on a Bos::Owned
doesn’t clone anything.
use bos::{Bos, BosStr};
let mut hello: BosStr = Bos::Owned("Hello".to_owned());
hello.to_mut().push_str(", Barbara!");
assert_eq!(hello, "Hello, Barbara!");
Calling to_mut
on a Bos::Arc
only clones the inner data
if the reference count is greater than one.
use bos::{Bos, BosStr};
let mut hello: BosStr = Bos::Arc("Hello".to_owned().into());
hello.to_mut().push_str(", Barbara!");
assert_eq!(hello, "Hello, Barbara!");
Convert borrowed variants so that the new Bos
has a 'static
lifetime.
Examples
let b = BosStr::Borrowed("a");
let s = b.into_static();
assert_eq!(s, "a");
assert_matches::assert_matches!(s, BosStr::Owned(_));
Convert Self::Arc
from Arc<S>
to a new Arc<O>
.
This will clone the inner data.
This is unstable and only available with the unstable
feature.
Convert Self::Arc
from Arc<S>
to a new Arc<B>
.
This will clone the inner data.
This is unstable and only available with the unstable
feature.
Convert to a new Bos
that borrows from self
.
Examples
let o = BosStr::Owned("a".into());
let b = o.to_borrowed();
assert_eq!(b, "a");
assert_matches::assert_matches!(b, BosStr::Borrowed(_));
let a = BosStr::Rc(String::from("a").into());
let b = a.to_borrowed();
assert_eq!(b, "a");
assert_matches::assert_matches!(b, BosStr::BorrowedRc(_));
Convert Bos::Owned
into Bos::Rc
.
Examples
let o = BosStr::Owned("a".into());
let s = o.into_shared();
assert_eq!(s, "a");
assert_matches::assert_matches!(s, BosStr::Rc(_));
This is unstable and only available with the unstable
feature.
Change Bos::Owned
into Bos::Rc
.
Examples
let mut a = BosStr::Owned("a".into());
a.make_shared();
assert_eq!(a, "a");
assert_matches::assert_matches!(a, BosStr::Rc(_));
Trait Implementations
Performs the +=
operation. Read more
impl<'de, 'b, B: ?Sized, O, S: ?Sized> Deserialize<'de> for Bos<'b, B, O, S> where
O: Deserialize<'de>,
impl<'de, 'b, B: ?Sized, O, S: ?Sized> Deserialize<'de> for Bos<'b, B, O, S> where
O: Deserialize<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl<'b, B: ?Sized, O, S: ?Sized> PartialOrd<&'_ B> for Bos<'b, B, O, S> where
B: PartialOrd,
O: Borrow<B>,
S: Borrow<B>,
impl<'b, B: ?Sized, O, S: ?Sized> PartialOrd<&'_ B> for Bos<'b, B, O, S> where
B: PartialOrd,
O: Borrow<B>,
S: Borrow<B>,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<'b, B: ?Sized, O, S: ?Sized> PartialOrd<B> for Bos<'b, B, O, S> where
B: PartialOrd,
O: Borrow<B>,
S: Borrow<B>,
impl<'b, B: ?Sized, O, S: ?Sized> PartialOrd<B> for Bos<'b, B, O, S> where
B: PartialOrd,
O: Borrow<B>,
S: Borrow<B>,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<'b, B: ?Sized, O, S: ?Sized> PartialOrd<Bos<'b, B, O, S>> for Bos<'b, B, O, S> where
B: PartialOrd,
O: Borrow<B>,
S: Borrow<B>,
impl<'b, B: ?Sized, O, S: ?Sized> PartialOrd<Bos<'b, B, O, S>> for Bos<'b, B, O, S> where
B: PartialOrd,
O: Borrow<B>,
S: Borrow<B>,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl<'b, B, O = B, S = O> !RefUnwindSafe for Bos<'b, B, O, S>
impl<'b, B, O = B, S = O> !UnwindSafe for Bos<'b, B, O, S>
Blanket Implementations
Mutably borrows from an owned value. Read more