Skip to main content

TryCow

Enum TryCow 

pub enum TryCow<'a, B>
where B: 'a + TryToOwned + ?Sized,
{ Borrowed(&'a B), Owned(<B as TryToOwned>::Owned), }
Expand description

Like std::borrow::Cow but returns OutOfMemory errors for various APIs that force allocation of an owned copy.

Variants§

§

Borrowed(&'a B)

Borrowed data.

§

Owned(<B as TryToOwned>::Owned)

Owned data.

Implementations§

§

impl<'a, B> TryCow<'a, B>
where B: TryToOwned + ?Sized,

pub fn to_mut(&mut self) -> Result<&mut <B as TryToOwned>::Owned, OutOfMemory>

Same as std::borrow::Cow::to_mut but returns an OutOfMemory error on allocation failure.

pub fn into_owned(self) -> Result<<B as TryToOwned>::Owned, OutOfMemory>

Same as std::borrow::Cow::into_owned but returns an OutOfMemory error on allocation failure.

Trait Implementations§

§

impl<B> AsRef<B> for TryCow<'_, B>
where B: TryToOwned + ?Sized,

§

fn as_ref(&self) -> &B

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

impl<'a, B> Borrow<B> for TryCow<'a, B>
where B: TryToOwned + ?Sized,

§

fn borrow(&self) -> &B

Immutably borrows from an owned value. Read more
§

impl<B> Debug for TryCow<'_, B>
where B: Debug + TryToOwned + ?Sized, <B as TryToOwned>::Owned: Debug,

§

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

Formats the value using the given formatter. Read more
§

impl<B> Default for TryCow<'_, B>
where B: TryToOwned + ?Sized, <B as TryToOwned>::Owned: Default,

§

fn default() -> TryCow<'_, B>

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

impl<B> Deref for TryCow<'_, B>
where B: TryToOwned + ?Sized,

§

type Target = B

The resulting type after dereferencing.
§

fn deref(&self) -> &B

Dereferences the value.
§

impl<'a, B> From<&'a B> for TryCow<'a, B>
where B: 'a + TryToOwned + ?Sized,

§

fn from(b: &'a B) -> TryCow<'a, B>

Converts to this type from the input type.
§

impl<B> Hash for TryCow<'_, B>
where B: Hash + TryToOwned + ?Sized,

§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<B> Ord for TryCow<'_, B>
where B: Ord + TryToOwned + ?Sized,

§

fn cmp(&self, other: &TryCow<'_, B>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
§

impl<B> PartialEq for TryCow<'_, B>
where B: PartialEq + TryToOwned + ?Sized,

§

fn eq(&self, other: &TryCow<'_, 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.
§

impl<B> PartialOrd for TryCow<'_, B>
where B: PartialOrd + TryToOwned + ?Sized,

§

fn partial_cmp(&self, other: &TryCow<'_, B>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

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

impl<B> TryClone for TryCow<'_, B>
where B: TryToOwned + ?Sized,

§

fn try_clone(&self) -> Result<TryCow<'_, B>, OutOfMemory>

Attempt to clone self, returning an error if any allocation fails during cloning.
§

fn clone_panic_on_oom(&self) -> Self

Clone self, panicking on allocation failure.
§

impl<B> Eq for TryCow<'_, B>
where B: Eq + TryToOwned + ?Sized,

Auto Trait Implementations§

§

impl<'a, B> Freeze for TryCow<'a, B>
where <B as TryToOwned>::Owned: Freeze, B: ?Sized,

§

impl<'a, B> RefUnwindSafe for TryCow<'a, B>

§

impl<'a, B> Send for TryCow<'a, B>
where <B as TryToOwned>::Owned: Send, B: Sync + ?Sized,

§

impl<'a, B> Sync for TryCow<'a, B>
where <B as TryToOwned>::Owned: Sync, B: Sync + ?Sized,

§

impl<'a, B> Unpin for TryCow<'a, B>
where <B as TryToOwned>::Owned: Unpin, B: ?Sized,

§

impl<'a, B> UnwindSafe for TryCow<'a, B>

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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> TryToOwned for T
where T: TryClone,

§

type Owned = T

The owned version of this type.
§

fn try_to_owned(&self) -> Result<<T as TryToOwned>::Owned, OutOfMemory>

Try to allocate an owned version of self.