[][src]Struct beef::generic::Cow

pub struct Cow<'a, T: Beef + ?Sized + 'a, U: Capacity> { /* fields omitted */ }

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.

Methods

impl<'_, T: ?Sized, U> Cow<'_, T, U> where
    T: Beef,
    U: Capacity, 
[src]

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

Owned data.

Example

use beef::Cow;

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

impl<'a, T: ?Sized, U> Cow<'a, T, U> where
    T: Beef,
    U: Capacity, 
[src]

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

Borrowed data.

Example

use beef::Cow;

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

pub fn into_owned(self) -> T::Owned[src]

Extracts the owned data.

Clones the data if it is not already owned.

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

Extracts borrowed data.

Panics: If the data is owned.

pub fn is_borrowed(&self) -> bool[src]

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

pub fn is_owned(&self) -> bool[src]

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

impl<'a> Cow<'a, str, Wide>[src]

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

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

impl<'a> Cow<'a, str, Lean>[src]

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

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

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

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

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

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

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

type Target = T

The resulting type after dereferencing.

impl<'_, T: ?Sized, U> Display for Cow<'_, T, U> where
    T: Beef + Display,
    U: Capacity, 
[src]

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

impl<'a, T: Eq + Beef + ?Sized + 'a, U: Eq + Capacity> Eq for Cow<'a, T, U> where
    T::PointerT: Eq,
    U::Field: Eq
[src]

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

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

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

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

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

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

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

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

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

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

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

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

impl<'_, '_, A: ?Sized, B: ?Sized, U, V> PartialEq<Cow<'_, B, V>> for Cow<'_, A, U> where
    A: Beef,
    B: Beef,
    U: Capacity,
    V: Capacity,
    A: PartialEq<B>, 
[src]

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

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

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

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

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

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

impl<'_, T: Beef + Send + ?Sized, U: Capacity> Send for Cow<'_, T, U>[src]

impl<'a, T: Beef + ?Sized + 'a, U: Capacity> StructuralEq for Cow<'a, T, U>[src]

impl<'_, T: Beef + Sync + ?Sized, U: Capacity> Sync for Cow<'_, T, U>[src]

Auto Trait Implementations

impl<'a, T: ?Sized, U> Unpin for Cow<'a, T, U> where
    <U as Capacity>::Field: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.