pub struct Cow<'a, T: Beef + ?Sized + 'a, U: Capacity> { /* private fields */ }
Expand description
A clone-on-write smart pointer, mostly compatible with std::borrow::Cow
.
This type is using a generic U: Capacity
. Use either beef::Cow
or beef::lean::Cow
in your code.
Implementations
sourceimpl<'a, T, U> Cow<'a, T, U> where
T: Beef + ?Sized,
U: Capacity,
impl<'a, T, U> Cow<'a, T, U> where
T: Beef + ?Sized,
U: Capacity,
sourcepub fn into_owned(self) -> T::Owned
pub fn into_owned(self) -> T::Owned
Extracts the owned data.
Clones the data if it is not already owned.
sourcepub fn unwrap_borrowed(self) -> &'a T
pub fn unwrap_borrowed(self) -> &'a T
Extracts borrowed data.
Panics: If the data is owned.
sourcepub fn is_borrowed(&self) -> bool
pub fn is_borrowed(&self) -> bool
Returns true
if data is borrowed or had no capacity.
Example
use beef::Cow;
let borrowed: Cow<str> = Cow::borrowed("Borrowed");
let no_capacity: Cow<str> = Cow::owned(String::new());
let owned: Cow<str> = Cow::owned(String::from("Owned"));
assert_eq!(borrowed.is_borrowed(), true);
assert_eq!(no_capacity.is_borrowed(), true);
assert_eq!(owned.is_borrowed(), false);
sourcepub fn is_owned(&self) -> bool
pub fn is_owned(&self) -> bool
Returns true
if data is owned and has non-0 capacity.
Example
use beef::Cow;
let borrowed: Cow<str> = Cow::borrowed("Borrowed");
let no_capacity: Cow<str> = Cow::owned(String::new());
let owned: Cow<str> = Cow::owned(String::from("Owned"));
assert_eq!(borrowed.is_owned(), false);
assert_eq!(no_capacity.is_owned(), false);
assert_eq!(owned.is_owned(), true);
Trait Implementations
sourceimpl<T, U> Ord for Cow<'_, T, U> where
T: Ord + Beef + ?Sized,
U: Capacity,
impl<T, U> Ord for Cow<'_, T, U> where
T: Ord + Beef + ?Sized,
U: Capacity,
sourceimpl<A, B, U, V> PartialEq<Cow<'_, B, V>> for Cow<'_, A, U> where
A: Beef + ?Sized,
B: Beef + ?Sized,
U: Capacity,
V: Capacity,
A: PartialEq<B>,
impl<A, B, U, V> PartialEq<Cow<'_, B, V>> for Cow<'_, A, U> where
A: Beef + ?Sized,
B: Beef + ?Sized,
U: Capacity,
V: Capacity,
A: PartialEq<B>,
sourceimpl<U, T> PartialEq<Vec<T, Global>> for Cow<'_, [T], U> where
U: Capacity,
T: Clone + PartialEq,
impl<U, T> PartialEq<Vec<T, Global>> for Cow<'_, [T], U> where
U: Capacity,
T: Clone + PartialEq,
sourceimpl<A, B, U, V> PartialOrd<Cow<'_, B, V>> for Cow<'_, A, U> where
A: Beef + ?Sized + PartialOrd<B>,
B: Beef + ?Sized,
U: Capacity,
V: Capacity,
impl<A, B, U, V> PartialOrd<Cow<'_, B, V>> for Cow<'_, A, U> where
A: Beef + ?Sized + PartialOrd<B>,
B: Beef + ?Sized,
U: Capacity,
V: Capacity,
sourcefn partial_cmp(&self, other: &Cow<'_, B, V>) -> Option<Ordering>
fn partial_cmp(&self, other: &Cow<'_, B, V>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<T, U> Eq for Cow<'_, T, U> where
T: Eq + Beef + ?Sized,
U: Capacity,
impl<T, U> Send for Cow<'_, T, U> where
U: Capacity,
T: Beef + Sync + ?Sized,
T::Owned: Send,
impl<T, U> Sync for Cow<'_, T, U> where
U: Capacity,
T: Beef + Sync + ?Sized,
T::Owned: Sync,
impl<T, U> Unpin for Cow<'_, T, U> where
U: Capacity,
T: Beef + ?Sized,
T::Owned: Unpin,
Auto Trait Implementations
impl<'a, T: ?Sized, U> RefUnwindSafe for Cow<'a, T, U> where
T: RefUnwindSafe,
<U as Capacity>::Field: RefUnwindSafe,
<T as Beef>::PointerT: RefUnwindSafe,
impl<'a, T: ?Sized, U> UnwindSafe for Cow<'a, T, U> where
T: RefUnwindSafe,
<U as Capacity>::Field: UnwindSafe,
<T as Beef>::PointerT: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more