[][src]Enum cervine::Cow

pub enum Cow<'a, T, R: ?Sized> {
    Owned(T),
    Borrowed(&'a R),
}

Cow is a clone-on-write smart pointer largely analogous to alloc::borrow::Cow, with one key difference:
Instead of requiring ToOwned, the owned and borrowed type are both configurable and most methods require T: Borrow<R>.

serde::Deserialize and serde::Serialize are only available with the "serde" feature.

Variants

Owned(T)
Borrowed(&'a R)

Implementations

impl<'a, T: Borrow<R>, R: ?Sized> Cow<'a, T, R>[src]

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

Returns whether this value is a borrowed variant.

Example

use cervine::Cow;

let borrowed: Cow<String, _> = Cow::Borrowed("borrowed");
let owned: Cow<_, str> = Cow::Owned("owned".to_string());

assert!(borrowed.is_borrowed());
assert!(!owned.is_borrowed());

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

Returns whether this value is an owned variant.

Example

use cervine::Cow;

let borrowed: Cow<String, _> = Cow::Borrowed("borrowed");
let owned: Cow<_, str> = Cow::Owned("owned".to_string());

assert!(!borrowed.is_owned());
assert!(owned.is_owned());

impl<'a, T: From<&'a R>, R: ?Sized> Cow<'a, T, R>[src]

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

Converts this value into T.

Example

use cervine::Cow;

let borrowed = Cow::Borrowed("borrowed");
let owned: Cow<_, str> = Cow::Owned("owned".into());

let not_borrowed: String = borrowed.into_owned(); // Clones the `String`.
let owned: String = owned.into_owned(); // Moves the `String`.

pub fn make_mut(&mut self) -> &mut T[src]

Retrieves a mutable reference to the contained T.

If this value is a borrowed variant, it is converted in place into an owned variant first.

Example

use cervine::Cow;

let mut borrowed = Cow::Borrowed("borrowed");
let mut owned: Cow<_, str> = Cow::Owned("owned".into());

let mutable_copy: &mut String = borrowed.make_mut(); // Clones the `String`.
let mutable_borrow: &mut String = owned.make_mut();

impl<'a, T: TryFrom<&'a R>, R: ?Sized> Cow<'a, T, R>[src]

pub fn try_into_owned(self) -> Result<T, T::Error>[src]

Converts this value into T if possible.

Example

use cervine::Cow;

let borrowed = Cow::Borrowed("borrowed");
let owned: Cow<_, str> = Cow::Owned("owned".into());

let not_borrowed: String = borrowed.try_into_owned()?; // Clones the `String`.
let owned: String = owned.try_into_owned()?; // Moves the `String`.

Errors

pub fn try_make_mut(&mut self) -> Result<&mut T, T::Error>[src]

Retrieves a mutable reference to the contained T, if possible.

If this value is a borrowed variant, an attempt is made to convert it in place into an owned variant first.

Example

use cervine::Cow;

let mut borrowed = Cow::Borrowed("borrowed");
let mut owned: Cow<_, str> = Cow::Owned("owned".into());

let mutable_copy: &mut String = borrowed.try_make_mut()?; // Clones the `String`.
let mutable_borrow: &mut String = owned.try_make_mut()?; // Moves the `String`.

Errors

Trait Implementations

impl<'a, T: AsRef<R>, R: ?Sized> AsRef<R> for Cow<'a, T, R>[src]

impl<'a, T: Borrow<R>, R: ?Sized> Borrow<R> for Cow<'a, T, R>[src]

impl<'a, T: Clone, R: ?Sized> Clone for Cow<'a, T, R>[src]

impl<'a, T: Copy, R: ?Sized> Copy for Cow<'a, T, R>[src]

impl<'a, T: Debug, R: Debug + ?Sized> Debug for Cow<'a, T, R>[src]

impl<'a, T: Default, R: ?Sized> Default for Cow<'a, T, R>[src]

impl<'a, T: Deref<Target = R>, R: ?Sized> Deref for Cow<'a, T, R>[src]

type Target = R

The resulting type after dereferencing.

impl<'a, T: Borrow<R>, R: Display + ?Sized> Display for Cow<'a, T, R>[src]

impl<'a, T: Borrow<R>, R: Eq + ?Sized> Eq for Cow<'a, T, R>[src]

impl<'a, T: Borrow<R>, R: Hash + ?Sized> Hash for Cow<'a, T, R>[src]

impl<'a, T: Borrow<R>, R: Ord + ?Sized> Ord for Cow<'a, T, R>[src]

impl<'a, T: Borrow<R>, R: PartialEq + ?Sized> PartialEq<Cow<'a, T, R>> for Cow<'a, T, R>[src]

impl<'a, T: Borrow<R>, R: PartialEq + ?Sized> PartialEq<R> for Cow<'a, T, R>[src]

impl<'a, T: Borrow<R>, R: PartialOrd + ?Sized> PartialOrd<Cow<'a, T, R>> for Cow<'a, T, R>[src]

impl<'a, T: Borrow<R>, R: PartialOrd + ?Sized> PartialOrd<R> for Cow<'a, T, R>[src]

Auto Trait Implementations

impl<'a, T, R: ?Sized> Send for Cow<'a, T, R> where
    R: Sync,
    T: Send

impl<'a, T, R: ?Sized> Sync for Cow<'a, T, R> where
    R: Sync,
    T: Sync

impl<'a, T, R: ?Sized> Unpin for Cow<'a, T, R> where
    T: 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, 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.