Enum core::borrow::CowUnstable [-]  [+] [src]

pub enum Cow<'a, T, B: 'a + ?Sized> where B: ToOwned<T> {
    Borrowed(&'a B),
    Owned(T),
}

A clone-on-write smart pointer.

Example

fn main() { use std::borrow::Cow; fn abs_all(input: &mut Cow<Vec<int>, [int]>) { for i in range(0, input.len()) { let v = input[i]; if v < 0 { // clones into a vector the first time (if not already owned) input.to_mut()[i] = -v; } } } }
use std::borrow::Cow;

fn abs_all(input: &mut Cow<Vec<int>, [int]>) {
    for i in range(0, input.len()) {
        let v = input[i];
        if v < 0 {
            // clones into a vector the first time (if not already owned)
            input.to_mut()[i] = -v;
        }
    }
}

Variants

Borrowed

Borrowed data.

Owned

Owned data.

Methods

impl<'a, T, B: ?Sized> Cow<'a, T, B> where B: ToOwned<T>

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

Acquire a mutable reference to the owned form of the data.

Copies the data if it is not already owned.

fn into_owned(self) -> T

Extract the owned data.

Copies the data if it is not already owned.

fn is_borrowed(&self) -> bool

Returns true if this Cow wraps a borrowed value

fn is_owned(&self) -> bool

Returns true if this Cow wraps an owned value

Trait Implementations

impl<'a, T, B: ?Sized> IntoCow<'a, T, B> for Cow<'a, T, B> where B: ToOwned<T>

fn into_cow(self) -> Cow<'a, T, B>

impl<'a, T, B: ?Sized> Clone for Cow<'a, T, B> where B: ToOwned<T>

fn clone(&self) -> Cow<'a, T, B>

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

impl<'a, T, B: ?Sized> Deref<B> for Cow<'a, T, B> where B: ToOwned<T>

fn deref(&self) -> &B

impl<'a, T, B: ?Sized> Eq for Cow<'a, T, B> where B: Eq + ToOwned<T>

impl<'a, T, B: ?Sized> Ord for Cow<'a, T, B> where B: Ord + ToOwned<T>

fn cmp(&self, other: &Cow<'a, T, B>) -> Ordering

impl<'a, 'b, T, U, B: ?Sized, C: ?Sized> PartialEq<Cow<'b, U, C>> for Cow<'a, T, B> where B: PartialEq<C> + ToOwned<T>, C: ToOwned<U>

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

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

impl<'a, T, B: ?Sized> PartialOrd for Cow<'a, T, B> where B: PartialOrd + ToOwned<T>

fn partial_cmp(&self, other: &Cow<'a, T, B>) -> Option<Ordering>

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

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

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

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

impl<'a, T, B: ?Sized> Show for Cow<'a, T, B> where B: Show + ToOwned<T>, T: Show

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

impl<'a, T, B: ?Sized, S> Hash<S> for Cow<'a, T, B> where B: Hash<S> + ToOwned<T>

fn hash(&self, state: &mut S)