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§
source§impl<'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§
source§impl<T, U> Ord for Cow<'_, T, U>
impl<T, U> Ord for Cow<'_, T, U>
source§impl<U, T> PartialEq<&[T]> for Cow<'_, [T], U>
impl<U, T> PartialEq<&[T]> for Cow<'_, [T], U>
source§impl<U> PartialEq<&str> for Cow<'_, str, U>where
U: Capacity,
impl<U> PartialEq<&str> for Cow<'_, str, U>where
U: Capacity,
source§impl<U, T> PartialEq<Cow<'_, [T], U>> for &[T]
impl<U, T> PartialEq<Cow<'_, [T], U>> for &[T]
source§impl<U, T> PartialEq<Cow<'_, [T], U>> for [T]
impl<U, T> PartialEq<Cow<'_, [T], U>> for [T]
source§impl<U, T> PartialEq<Cow<'_, [T], U>> for Vec<T>
impl<U, T> PartialEq<Cow<'_, [T], U>> for Vec<T>
source§impl<A, B, U, V> PartialEq<Cow<'_, B, V>> for Cow<'_, A, U>
impl<A, B, U, V> PartialEq<Cow<'_, B, V>> for Cow<'_, A, U>
source§impl<U> PartialEq<Cow<'_, str, U>> for &strwhere
U: Capacity,
impl<U> PartialEq<Cow<'_, str, U>> for &strwhere
U: Capacity,
source§impl<U> PartialEq<Cow<'_, str, U>> for Stringwhere
U: Capacity,
impl<U> PartialEq<Cow<'_, str, U>> for Stringwhere
U: Capacity,
source§impl<U> PartialEq<Cow<'_, str, U>> for strwhere
U: Capacity,
impl<U> PartialEq<Cow<'_, str, U>> for strwhere
U: Capacity,
source§impl<U> PartialEq<String> for Cow<'_, str, U>where
U: Capacity,
impl<U> PartialEq<String> for Cow<'_, str, U>where
U: Capacity,
source§impl<U, T> PartialEq<Vec<T>> for Cow<'_, [T], U>
impl<U, T> PartialEq<Vec<T>> for Cow<'_, [T], U>
source§impl<A, B, U, V> PartialOrd<Cow<'_, B, V>> for Cow<'_, A, U>
impl<A, B, U, V> PartialOrd<Cow<'_, B, V>> for Cow<'_, A, U>
1.0.0 · source§fn 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 moreimpl<T, U> Eq for Cow<'_, T, U>
impl<T, U> Send for Cow<'_, T, U>
impl<T, U> Sync for Cow<'_, T, U>
impl<T, U> Unpin for Cow<'_, T, U>
Auto Trait Implementations§
impl<'a, T: ?Sized, U> Freeze for Cow<'a, T, U>where
<U as Capacity>::Field: Freeze,
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>
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