flex_alloc::borrow

Enum Cow

Source
pub enum Cow<'b, T: ToOwnedIn<A> + ?Sized, A: Allocator> {
    Borrowed(&'b T),
    Owned(Owned<T, A>),
}
Expand description

Representation of either an owned or borrowed instance of a type.

Variants§

§

Borrowed(&'b T)

The borrowed variant, limited by a lifetime.

§

Owned(Owned<T, A>)

The owned variant.

Implementations§

Source§

impl<'b, T: ToOwnedIn<A> + ?Sized, A: Allocator> Cow<'b, T, A>

Source

pub fn is_borrowed(&self) -> bool

Determine if this instance is borrowed.

Source

pub fn is_owned(&self) -> bool

Determine if this instance is owned.

Source

pub fn to_mut(&mut self) -> &mut Owned<T, A>
where A: Default + Allocator,

If necessary, convert self into an owned instance. Return a mutable reference to the owned instance.

Source

pub fn to_mut_in<I>(&mut self, alloc_in: I) -> &mut Owned<T, A>
where I: AllocateIn<Alloc = A>,

If necessary, convert self into an owned instance given an allocation target. Return a mutable reference to the owned instance.

Source

pub fn into_owned(self) -> Owned<T, A>
where A: Default + Allocator,

If necessary, convert self into an owned instance. Unwrap and return the owned instance.

Source

pub fn into_owned_in<I>(self, alloc_in: I) -> Owned<T, A>
where I: AllocateIn<Alloc = A>,

If necessary, convert self into an owned instance given an allocation target. Unwrap and return the owned instance.

Source

pub fn try_into_owned(self) -> Result<Owned<T, A>, StorageError>
where A: Default + Allocator,

If necessary, try to convert self into an owned instance. Unwrap and return the owned instance or a storage error.

Source

pub fn try_into_owned_in<I>( self, storage: I, ) -> Result<Owned<T, A>, StorageError>
where I: AllocateIn<Alloc = A>,

If necessary, try to convert self into an owned instance given an allocation target. Unwrap and return the owned instance or a storage error.

Trait Implementations§

Source§

impl<T: ToOwnedIn<A> + ?Sized, A: Allocator> AsRef<T> for Cow<'_, T, A>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: ToOwnedIn<A> + ?Sized, A: Allocator> Borrow<T> for Cow<'_, T, A>

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T: ToOwnedIn<A> + ?Sized, A: Allocator> Clone for Cow<'_, T, A>
where Owned<T, A>: Clone,

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, A: Allocator> ConstDefault for Cow<'_, T, A>
where T: ToOwnedIn<A> + ?Sized, T::Owned: ConstDefault,

Source§

const DEFAULT: Self = _

The constant default value.
Source§

impl<T, A: Allocator> Debug for Cow<'_, T, A>
where T: ToOwnedIn<A> + Debug + ?Sized, Owned<T, A>: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ToOwnedIn<A> + ?Sized, A: Allocator> Default for Cow<'_, T, A>
where Owned<T, A>: Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: ToOwnedIn<A> + ?Sized, A: Allocator> Deref for Cow<'_, T, A>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T, A: Allocator> Display for Cow<'_, T, A>
where T: ToOwnedIn<A> + Display + ?Sized, Owned<T, A>: Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T: Clone, A: Allocator, const N: usize> From<&'a [T; N]> for Cow<'a, [T], A>

Source§

fn from(s: &'a [T; N]) -> Cow<'a, [T], A>

Converts to this type from the input type.
Source§

impl<'b, T: ToOwnedIn<A> + ?Sized, A: Allocator> From<&'b T> for Cow<'b, T, A>

Source§

fn from(borrow: &'b T) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: Clone, A: Allocator> From<&'a Vec<T, A>> for Cow<'a, [T], A>

Source§

fn from(vec: &'a Vec<T, A>) -> Cow<'a, [T], A>

Converts to this type from the input type.
Source§

impl<'a, T: Clone, A: Allocator, const N: usize> From<&'a mut [T; N]> for Cow<'a, [T], A>

Source§

fn from(s: &'a mut [T; N]) -> Cow<'a, [T], A>

Converts to this type from the input type.
Source§

impl<'b, T: ToOwnedIn<A> + ?Sized, A: Allocator> From<&'b mut T> for Cow<'b, T, A>

Source§

fn from(borrow: &'b mut T) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: Clone, A: Allocator> From<Vec<T, A>> for Cow<'a, [T], A>

Source§

fn from(vec: Vec<T, A>) -> Cow<'a, [T], A>

Converts to this type from the input type.
Source§

impl<'a, T: Clone, A: AllocatorDefault> FromIterator<T> for Cow<'a, [T], A>

Source§

fn from_iter<I: IntoIterator<Item = T>>(it: I) -> Cow<'a, [T], A>

Creates a value from an iterator. Read more
Source§

impl<'a, 'b, T, A: Allocator, U: ToOwnedIn<B> + ?Sized, B: Allocator> PartialEq<Cow<'b, U, B>> for Cow<'a, T, A>
where T: PartialEq<U> + ToOwnedIn<A> + ?Sized,

Source§

fn eq(&self, other: &Cow<'b, U, B>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T: ToOwnedIn<A> + Eq + ?Sized, A: Allocator> Eq for Cow<'a, T, A>

Auto Trait Implementations§

§

impl<'b, T, A> Freeze for Cow<'b, T, A>
where <T as ToOwnedIn<A>>::Owned: Freeze, T: ?Sized,

§

impl<'b, T, A> RefUnwindSafe for Cow<'b, T, A>
where <T as ToOwnedIn<A>>::Owned: RefUnwindSafe, T: RefUnwindSafe + ?Sized,

§

impl<'b, T, A> Send for Cow<'b, T, A>
where <T as ToOwnedIn<A>>::Owned: Send, T: Sync + ?Sized,

§

impl<'b, T, A> Sync for Cow<'b, T, A>
where <T as ToOwnedIn<A>>::Owned: Sync, T: Sync + ?Sized,

§

impl<'b, T, A> Unpin for Cow<'b, T, A>
where <T as ToOwnedIn<A>>::Owned: Unpin, T: ?Sized,

§

impl<'b, T, A> UnwindSafe for Cow<'b, T, A>
where <T as ToOwnedIn<A>>::Owned: UnwindSafe, T: RefUnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, A> ToOwnedIn<A> for T
where T: Clone + 'static, A: Allocator,

Source§

type Owned = T

The owned representation of this type.
Source§

fn try_to_owned_in<I>( &self, _alloc_in: I, ) -> Result<<T as ToOwnedIn<A>>::Owned, StorageError>
where I: AllocateIn<Alloc = A>,

To to create an owned copy of this instance in a given allocation target.
Source§

fn to_owned_in<I>(&self, alloc_in: I) -> Self::Owned
where I: AllocateIn<Alloc = A>,

Create an owned copy of this instance in a given allocation target.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.