pub enum Cow<'a, T>where
T: Cowable,{
Borrowed(CowableBorrowed<'a, T>),
Owned(CowableOwned<T>),
}
Expand description
A clone-on-write container that contains either the owned or borrowed version of some data.
Unlike std::borrow::Cow, this type may hold non-reference types with
internal references in the borrowed variant. T
is required to implement
Cowable.
§Notes
- Important: The implementations of PartialEq, Eq, PartialOrd and Ord assume that the results are the same regardless of which combination of borrowed and owned versions are being compared.
- Some traits cannot have blanket implementations without support for specialization in Rust, such as the From trait. Where possible the functionality is provided by intrinsic methods instead.
Variants§
Implementations§
Source§impl<'a, T> Cow<'a, T>where
T: Cowable,
impl<'a, T> Cow<'a, T>where
T: Cowable,
Sourcepub fn borrowed(borrowed: impl Into<CowableBorrowed<'a, T>>) -> Self
pub fn borrowed(borrowed: impl Into<CowableBorrowed<'a, T>>) -> Self
Create a new Cow containing borrowed data.
Sourcepub fn owned(owned: impl Into<CowableOwned<T>>) -> Self
pub fn owned(owned: impl Into<CowableOwned<T>>) -> Self
Create a new Cow containing owned data.
Sourcepub fn is_borrowed(&self) -> bool
pub fn is_borrowed(&self) -> bool
Return true if the data is borrowed.
Sourcepub fn unwrap_borrowed(self) -> CowableBorrowed<'a, T>
pub fn unwrap_borrowed(self) -> CowableBorrowed<'a, T>
Unwrap the borrowed data, panicking if the data is owned.
Sourcepub fn unwrap_owned(self) -> CowableOwned<T>
pub fn unwrap_owned(self) -> CowableOwned<T>
Unwrap the owned data, panicking if the data is borrowed.
Source§impl<'a, T> Cow<'a, T>
impl<'a, T> Cow<'a, T>
Sourcepub fn to_mut(&mut self) -> &mut CowableOwned<T>
pub fn to_mut(&mut self) -> &mut CowableOwned<T>
If this Cow contains and owned value, return a mutable reference to it. If it contains a borrowed value, make it owned and return a mutable reference to this new value.
Sourcepub fn into_inner(self) -> CowableOwned<T>
pub fn into_inner(self) -> CowableOwned<T>
Unwrap this Cow into and owned value, calling ToOwned::into_owned if the data is borrowed.
Trait Implementations§
Source§impl<'a, T> Borrow<'a, BorrowCow<T>> for Cow<'a, T>where
T: Cowable,
CowableBorrowed<'a, T>: Borrow<'a, T::BorrowHkt>,
CowableOwned<T>: Borrow<'a, T::BorrowHkt>,
impl<'a, T> Borrow<'a, BorrowCow<T>> for Cow<'a, T>where
T: Cowable,
CowableBorrowed<'a, T>: Borrow<'a, T::BorrowHkt>,
CowableOwned<T>: Borrow<'a, T::BorrowHkt>,
Source§impl<'a, T> Ord for Cow<'a, T>where
T: Cowable,
CowableBorrowed<'a, T>: Ord + PartialOrd<CowableOwned<T>>,
CowableOwned<T>: Ord + PartialOrd<CowableBorrowed<'a, T>>,
impl<'a, T> Ord for Cow<'a, T>where
T: Cowable,
CowableBorrowed<'a, T>: Ord + PartialOrd<CowableOwned<T>>,
CowableOwned<T>: Ord + PartialOrd<CowableBorrowed<'a, T>>,
Source§impl<'a, T> PartialEq for Cow<'a, T>where
T: Cowable,
CowableBorrowed<'a, T>: PartialEq + PartialEq<CowableOwned<T>>,
CowableOwned<T>: PartialEq + PartialEq<CowableBorrowed<'a, T>>,
impl<'a, T> PartialEq for Cow<'a, T>where
T: Cowable,
CowableBorrowed<'a, T>: PartialEq + PartialEq<CowableOwned<T>>,
CowableOwned<T>: PartialEq + PartialEq<CowableBorrowed<'a, T>>,
Source§impl<'a, T> PartialOrd for Cow<'a, T>where
T: Cowable,
CowableBorrowed<'a, T>: PartialOrd + PartialOrd<CowableOwned<T>>,
CowableOwned<T>: PartialOrd + PartialOrd<CowableBorrowed<'a, T>>,
impl<'a, T> PartialOrd for Cow<'a, T>where
T: Cowable,
CowableBorrowed<'a, T>: PartialOrd + PartialOrd<CowableOwned<T>>,
CowableOwned<T>: PartialOrd + PartialOrd<CowableBorrowed<'a, T>>,
impl<'a, T> Copy for Cow<'a, T>
impl<'a, T> Eq for Cow<'a, T>where
T: Cowable,
CowableBorrowed<'a, T>: Eq + PartialEq<CowableOwned<T>>,
CowableOwned<T>: Eq + PartialEq<CowableBorrowed<'a, T>>,
Auto Trait Implementations§
impl<'a, T> Freeze for Cow<'a, T>
impl<'a, T> RefUnwindSafe for Cow<'a, T>where
<<T as Cowable>::BorrowHkt as BorrowHkt<'a>>::T: RefUnwindSafe,
<T as Cowable>::Owned: RefUnwindSafe,
impl<'a, T> Send for Cow<'a, T>
impl<'a, T> Sync for Cow<'a, T>
impl<'a, T> Unpin for Cow<'a, T>
impl<'a, T> UnwindSafe for Cow<'a, T>where
<<T as Cowable>::BorrowHkt as BorrowHkt<'a>>::T: UnwindSafe,
<T as Cowable>::Owned: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more