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

pub enum Cow<'a, T, B: ToOwned<T> + 'a> {
    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: ToOwned<T>> Cow<'a, T, B>

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.

Trait Implementations

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

fn deref(&self) -> &B