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<'de, 'a, T, U> Deserialize<'de> for Cow<'a, [T], U>where
[T]: Beef,
U: Capacity,
<[T] as ToOwned>::Owned: Deserialize<'de>,
impl<'de, 'a, T, U> Deserialize<'de> for Cow<'a, [T], U>where [T]: Beef, U: Capacity, <[T] as ToOwned>::Owned: Deserialize<'de>,
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<'de, 'a, U> Deserialize<'de> for Cow<'a, str, U>where
U: Capacity,
'de: 'a,
impl<'de, 'a, U> Deserialize<'de> for Cow<'a, str, U>where U: Capacity, 'de: 'a,
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<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,
source§impl<U, T> PartialEq<&[T]> for Cow<'_, [T], U>where
U: Capacity,
T: Clone + PartialEq,
impl<U, T> PartialEq<&[T]> for Cow<'_, [T], U>where U: Capacity, T: Clone + PartialEq,
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]where
U: Capacity,
T: Clone + PartialEq,
impl<U, T> PartialEq<Cow<'_, [T], U>> for &[T]where U: Capacity, T: Clone + PartialEq,
source§impl<U, T> PartialEq<Cow<'_, [T], U>> for [T]where
U: Capacity,
T: Clone + PartialEq,
impl<U, T> PartialEq<Cow<'_, [T], U>> for [T]where U: Capacity, T: Clone + PartialEq,
source§impl<U, T> PartialEq<Cow<'_, [T], U>> for Vec<T>where
U: Capacity,
T: Clone + PartialEq,
impl<U, T> PartialEq<Cow<'_, [T], U>> for Vec<T>where U: Capacity, T: Clone + PartialEq,
source§impl<A, B, U, V> PartialEq<Cow<'_, B, V>> for Cow<'_, A, U>where
A: Beef + ?Sized + PartialEq<B>,
B: Beef + ?Sized,
U: Capacity,
V: Capacity,
impl<A, B, U, V> PartialEq<Cow<'_, B, V>> for Cow<'_, A, U>where A: Beef + ?Sized + PartialEq<B>, B: Beef + ?Sized, U: Capacity, V: 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<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, 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,
source§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,
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,
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>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§
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