Type Alias beef::Cow

source ·
pub type Cow<'a, T> = Cow<'a, T, Wide>;
Expand description

Compact three word Cow that puts the ownership tag in capacity. This is a type alias, for documentation see beef::generic::Cow.

Aliased Type§

struct Cow<'a, T> { /* private fields */ }

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

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