Enum bos::Abos [−][src]
#[non_exhaustive]
pub enum Abos<'b, B: ?Sized, O = B, S: ?Sized = O> where
B: 'static + ?Sized,
O: 'static,
S: 'static + ?Sized, {
Static(&'static B),
Borrowed(&'b B),
Owned(O),
BorrowedArc(&'b Arc<S>),
Arc(Arc<S>),
}Expand description
Atomic 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 Static
0: &'static BTuple Fields of Borrowed
0: &'b BTuple Fields of BorrowedArc
0: &'b Arc<S>Tuple Fields of Arc
0: Arc<S>Implementations
Extracts the owned data.
Clones the data if it is not already owned.
Examples
Calling into_owned on a Abos::Borrowed clones the inner data.
use bos::{Abos, AbosStr};
let abos: AbosStr = Abos::Borrowed("Hello!");
let owned: String = abos.into_owned();
assert_eq!(owned, "Hello!");Calling into_owned on a Abos::Owned doesn’t clone anything.
use bos::{Abos, AbosStr};
let abos: AbosStr = Abos::Owned("Hello!".to_owned());
let owned: String = abos.into_owned();
assert_eq!(owned, "Hello!");Calling into_owned on a Abos::Arc only clones the inner data
if the reference count is greater than one.
use bos::{Abos, AbosStr};
let bos: AbosStr = Abos::Arc("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 an Abos::Borrowed clones the inner data.
use bos::{Abos, AbosStr};
let mut hello: AbosStr = Abos::Borrowed("Hello");
hello.to_mut().push_str(", Barbara!");
assert_eq!(hello, "Hello, Barbara!");Calling to_mut on an Abos::Owned doesn’t clone anything.
use bos::{Abos, AbosStr};
let mut hello: AbosStr = Abos::Owned("Hello".to_owned());
hello.to_mut().push_str(", Barbara!");
assert_eq!(hello, "Hello, Barbara!");Calling to_mut on an Abos::Arc only clones the inner data
if the reference count is greater than one.
use bos::{Abos, AbosStr};
let mut hello: AbosStr = Abos::Arc("Hello".to_owned().into());
hello.to_mut().push_str(", Barbara!");
assert_eq!(hello, "Hello, Barbara!");Convert borrowed variants so that the new Abos has a 'static lifetime.
Examples
let b = AbosStr::Borrowed("a");
let s = b.into_static();
assert_eq!(s, "a");
assert_matches::assert_matches!(s, AbosStr::Owned(_));Extracts the shared data.
Converting B or O to Arc<S> may clone the data.
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 Abos that borrows from self.
Examples
let o = AbosStr::Owned("a".into());
let b = o.to_borrowed();
assert_eq!(b, "a");
assert_matches::assert_matches!(b, AbosStr::Borrowed(_));let a = AbosStr::Arc(String::from("a").into());
let b = a.to_borrowed();
assert_eq!(b, "a");
assert_matches::assert_matches!(b, AbosStr::BorrowedArc(_));Convert Abos::Owned into Abos::Arc.
Examples
let o = AbosStr::Owned("a".into());
let s = o.into_shared();
assert_eq!(s, "a");
assert_matches::assert_matches!(s, AbosStr::Arc(_));This is unstable and only available with the unstable feature.
Change Abos::Owned into Abos::Arc.
Examples
let mut a = AbosStr::Owned("a".into());
a.make_shared();
assert_eq!(a, "a");
assert_matches::assert_matches!(a, AbosStr::Arc(_));Trait Implementations
Performs the += operation. Read more
impl<'de, 'b, B: ?Sized, O, S: ?Sized> Deserialize<'de> for Abos<'b, B, O, S> where
O: Deserialize<'de>,
impl<'de, 'b, B: ?Sized, O, S: ?Sized> Deserialize<'de> for Abos<'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 Abos<'b, B, O, S> where
B: PartialOrd,
O: Borrow<B>,
S: Borrow<B>,
impl<'b, B: ?Sized, O, S: ?Sized> PartialOrd<&'_ B> for Abos<'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<Abos<'b, B, O, S>> for Abos<'b, B, O, S> where
B: PartialOrd,
O: Borrow<B>,
S: Borrow<B>,
impl<'b, B: ?Sized, O, S: ?Sized> PartialOrd<Abos<'b, B, O, S>> for Abos<'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 Abos<'b, B, O, S> where
B: PartialOrd,
O: Borrow<B>,
S: Borrow<B>,
impl<'b, B: ?Sized, O, S: ?Sized> PartialOrd<B> for Abos<'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: ?Sized, O, S: ?Sized> RefUnwindSafe for Abos<'b, B, O, S> where
B: RefUnwindSafe,
O: RefUnwindSafe,
S: RefUnwindSafe,
impl<'b, B: ?Sized, O, S: ?Sized> Send for Abos<'b, B, O, S> where
B: Sync,
O: Send,
S: Send + Sync,
impl<'b, B: ?Sized, O, S: ?Sized> Sync for Abos<'b, B, O, S> where
B: Sync,
O: Sync,
S: Send + Sync,
impl<'b, B: ?Sized, O, S: ?Sized> UnwindSafe for Abos<'b, B, O, S> where
B: RefUnwindSafe,
O: UnwindSafe,
S: RefUnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more