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