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
{ 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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Borrowed

Tuple Fields of Borrowed

0: &'b B
Owned

Tuple Fields of Owned

0: O
BorrowedArc

Tuple Fields of BorrowedArc

0: &'b Arc<S>
Arc

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 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(_));

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

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Performs the conversion.

Immutably borrows from an owned value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Creates an owned Abos with the default value for the contained owned type.

The resulting type after dereferencing.

Dereferences the value.

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.