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

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

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> IntoCow<'a, T, B> for Cow<'a, T, B>

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

impl<'a, T, B> Clone for Cow<'a, T, B>

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

fn clone_from(&mut self, &Cow<'a, T, B>)

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

fn deref(&self) -> &B

impl<'a, T, B> Eq for Cow<'a, T, B>

fn assert_receiver_is_total_eq(&self)

impl<'a, T, B> Ord for Cow<'a, T, B>

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

impl<'a, 'b, T, U, B, C> PartialEq<Cow<'b, U, C>> for Cow<'a, T, B>

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

fn ne(&self, &Cow<'b, U, C>) -> bool

impl<'a, T, B> PartialOrd<Cow<'a, T, B>> for Cow<'a, T, B>

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

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

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

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

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

impl<'a, T, B> Show for Cow<'a, T, B>

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

impl<'a, T, B, S> Hash<S> for Cow<'a, T, B>

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

impl<'a> PartialEq<String> for Cow<'a, String, str>

fn eq(&self, other: &String) -> bool

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

fn ne(&self, &String) -> bool

impl<'a, 'b> PartialEq<&'b str> for Cow<'a, String, str>

fn eq(&self, other: &&'b str) -> bool

fn ne(&self, other: &&'b str) -> bool

fn ne(&self, &&'b str) -> bool

impl<'a> Str for Cow<'a, String, str>

fn as_slice(&'b self) -> &'b str

impl<'a, A, B> PartialEq<Vec<B>> for Cow<'a, Vec<A>, [A]>

fn eq(&self, other: &Vec<B>) -> bool

fn ne(&self, other: &Vec<B>) -> bool

fn ne(&self, &Vec<B>) -> bool

impl<'a, 'b, A, B> PartialEq<&'b [B]> for Cow<'a, Vec<A>, [A]>

fn eq(&self, other: &&'b [B]) -> bool

fn ne(&self, other: &&'b [B]) -> bool

fn ne(&self, &&'b [B]) -> bool

impl<'a, 'b, A, B> PartialEq<&'b mut [B]> for Cow<'a, Vec<A>, [A]>

fn eq(&self, other: &&'b mut [B]) -> bool

fn ne(&self, other: &&'b mut [B]) -> bool

fn ne(&self, &&'b mut [B]) -> bool

impl<'a, T> FromIterator<T> for Cow<'a, Vec<T>, [T]>

fn from_iter<I: Iterator<T>>(it: I) -> Cow<'a, Vec<T>, [T]>