Struct beef::generic::Cow

source ·
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<T, U> Cow<'_, T, U>where T: Beef + ?Sized, U: Capacity,

source

pub fn owned(val: T::Owned) -> Self

Owned data.

Example
use beef::Cow;

let owned: Cow<str> = Cow::owned("I own my content".to_string());
source§

impl<'a, T, U> Cow<'a, T, U>where T: Beef + ?Sized, U: Capacity,

source

pub fn borrowed(val: &'a T) -> Self

Borrowed data.

Example
use beef::Cow;

let borrowed: Cow<str> = Cow::borrowed("I'm just a borrow");
source

pub fn into_owned(self) -> T::Owned

Extracts the owned data.

Clones the data if it is not already owned.

source

pub fn unwrap_borrowed(self) -> &'a T

Extracts borrowed data.

Panics: If the data is owned.

source

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);
source

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);
source§

impl<'a> Cow<'a, str, Wide>

source

pub const fn const_str(val: &'a str) -> Self

Borrowed data.

This is functionally identical to borrow. We use impl specialization to allow this function to be const.

Example
use beef::Cow;

const HELLO: Cow<str> = Cow::const_str("Hello");
source§

impl<'a> Cow<'a, str, Lean>

source

pub const fn const_str(val: &'a str) -> Self

Borrowed data.

This is functionally identical to borrow. We use impl specialization to allow this function to be const.

Example
use beef::lean::Cow;

const HELLO: Cow<str> = Cow::const_str("Hello");

Trait Implementations§

source§

impl<T, U> AsRef<T> for Cow<'_, T, U>where T: Beef + ?Sized, U: Capacity,

source§

fn as_ref(&self) -> &T

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

impl<T, U> Borrow<T> for Cow<'_, T, U>where T: Beef + ?Sized, U: Capacity,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<'a, T, U> Clone for Cow<'a, T, U>where T: Beef + ?Sized, U: Capacity,

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T, U> Debug for Cow<'_, T, U>where T: Beef + Debug + ?Sized, U: Capacity,

source§

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

Formats the value using the given formatter. Read more
source§

impl<'a, T, U> Default for Cow<'a, T, U>where T: Beef + ?Sized, U: Capacity, &'a T: Default,

source§

fn default() -> Self

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

impl<T, U> Deref for Cow<'_, T, U>where T: Beef + ?Sized, U: Capacity,

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &T

Dereferences the value.
source§

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>,

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,

source§

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> Display for Cow<'_, T, U>where T: Beef + Display + ?Sized, U: Capacity,

source§

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

Formats the value using the given formatter. Read more
source§

impl<T, U> Drop for Cow<'_, T, U>where T: Beef + ?Sized, U: Capacity,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'a, T, U> From<&'a T> for Cow<'a, T, U>where T: Beef + ?Sized, U: Capacity,

source§

fn from(val: &'a T) -> Self

Converts to this type from the input type.
source§

impl<'a, T, U> From<Cow<'a, T>> for Cow<'a, T, U>where T: Beef + ?Sized, U: Capacity,

source§

fn from(stdcow: StdCow<'a, T>) -> Self

Converts to this type from the input type.
source§

impl<'a, T, U> From<Cow<'a, T, U>> for StdCow<'a, T>where T: Beef + ?Sized, U: Capacity,

source§

fn from(cow: Cow<'a, T, U>) -> Self

Converts to this type from the input type.
source§

impl<U> From<String> for Cow<'_, str, U>where U: Capacity,

source§

fn from(s: String) -> Self

Converts to this type from the input type.
source§

impl<T, U> From<Vec<T, Global>> for Cow<'_, [T], U>where T: Clone, U: Capacity,

source§

fn from(v: Vec<T>) -> Self

Converts to this type from the input type.
source§

impl<T, U> Hash for Cow<'_, T, U>where T: Hash + Beef + ?Sized, U: Capacity,

source§

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

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
source§

impl<T, U> Ord for Cow<'_, T, U>where T: Ord + Beef + ?Sized, U: Capacity,

source§

fn cmp(&self, other: &Self) -> Ordering

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

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

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

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

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

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl<U, T> PartialEq<&[T]> for Cow<'_, [T], U>where U: Capacity, T: Clone + PartialEq,

source§

fn eq(&self, other: &&[T]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<U> PartialEq<&str> for Cow<'_, str, U>where U: Capacity,

source§

fn eq(&self, other: &&str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<U, T> PartialEq<[T]> for Cow<'_, [T], U>where U: Capacity, T: Clone + PartialEq,

source§

fn eq(&self, other: &[T]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<U, T> PartialEq<Cow<'_, [T], U>> for &[T]where U: Capacity, T: Clone + PartialEq,

source§

fn eq(&self, other: &Cow<'_, [T], U>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<U, T> PartialEq<Cow<'_, [T], U>> for [T]where U: Capacity, T: Clone + PartialEq,

source§

fn eq(&self, other: &Cow<'_, [T], U>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<U, T> PartialEq<Cow<'_, [T], U>> for Vec<T>where U: Capacity, T: Clone + PartialEq,

source§

fn eq(&self, other: &Cow<'_, [T], U>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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,

source§

fn eq(&self, other: &Cow<'_, B, V>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<U> PartialEq<Cow<'_, str, U>> for &strwhere U: Capacity,

source§

fn eq(&self, other: &Cow<'_, str, U>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<U> PartialEq<Cow<'_, str, U>> for Stringwhere U: Capacity,

source§

fn eq(&self, other: &Cow<'_, str, U>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<U> PartialEq<Cow<'_, str, U>> for strwhere U: Capacity,

source§

fn eq(&self, other: &Cow<'_, str, U>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<U> PartialEq<String> for Cow<'_, str, U>where U: Capacity,

source§

fn eq(&self, other: &String) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<U, T> PartialEq<Vec<T, Global>> for Cow<'_, [T], U>where U: Capacity, T: Clone + PartialEq,

source§

fn eq(&self, other: &Vec<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<U> PartialEq<str> for Cow<'_, str, U>where U: Capacity,

source§

fn eq(&self, other: &str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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,

source§

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 · source§

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 · source§

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
1.0.0 · source§

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

This method 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

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

impl<T, U> Serialize for Cow<'_, T, U>where T: Beef + Serialize + ?Sized, U: Capacity,

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T, U> Eq for Cow<'_, T, U>where T: Eq + Beef + ?Sized, U: Capacity,

source§

impl<T, U> Send for Cow<'_, T, U>where U: Capacity, T: Beef + Sync + ?Sized, T::Owned: Send,

source§

impl<T, U> Sync for Cow<'_, T, U>where U: Capacity, T: Beef + Sync + ?Sized, T::Owned: Sync,

source§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,