Struct dairy::Cow [−][src]
Expand description
A clone-on-write smart pointer.
The type Cow
is a smart pointer providing clone-on-write functionality: it
can enclose and provide immutable access to borrowed data, and clone the
data lazily when mutation or ownership is required.
Cow
implements Deref
, which means that you can call non-mutating
methods directly on the data it encloses.
Implementations
Construct from owned data.
Examples
use dairy::Cow; let cow: Cow<str> = Cow::owned(String::from("moo"));
Returns true if the data is borrowed.
Examples
use dairy::Cow; let cow: Cow<str> = Cow::borrowed("moo"); assert!(cow.is_borrowed()); let cow: Cow<str> = Cow::owned(String::from("...moo?")); assert!(!cow.is_borrowed());
Returns true if the data is owned.
Examples
use dairy::Cow; let cow: Cow<str> = Cow::owned(String::from("moo")); assert!(cow.is_owned()); let cow: Cow<str> = Cow::borrowed("...moo?"); assert!(!cow.is_owned());
Converts into owned data.
Clones the data if it is not already owned.
Examples
Calling .into_owned()
on a borrowed Cow
clones the underlying data.
use dairy::Cow; let cow = Cow::borrowed("Moo!"); assert_eq!(cow.into_owned(), String::from("Moo!"));
Calling .into_owned()
on an owned Cow
is a noop.
use dairy::Cow; let cow: Cow<str> = Cow::owned(String::from("Moo!")); assert_eq!(cow.into_owned(), String::from("Moo!"));
Converts into boxed data.
Clones the data if it is not already owned.
Examples
Calling .into_boxed()
on a borrowed Cow
clones the underlying data.
use dairy::Cow; let cow = Cow::borrowed("Moo!"); assert_eq!(cow.into_boxed(), String::from("Moo!").into_boxed_str());
Calling .into_boxed()
on an owned Cow
is a noop.
use dairy::Cow; let cow: Cow<str> = Cow::owned(String::from("Moo!")); assert_eq!(cow.into_boxed(), String::from("Moo!").into_boxed_str());
Applies the given function to the owned data.
Clones the data if it is not already owned. This is useful because the
compact implementation is not able to provide a .to_mut()
method like
the standard library. This function allows you to modify the Cow
without moving it.
Examples
use dairy::Cow; let mut cow = Cow::borrowed("Moo!"); cow.apply(|s| s.make_ascii_uppercase()); assert_eq!(cow, "MOO!");
Trait Implementations
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Creates a value from an iterator. Read more
Creates a value from an iterator. Read more
Creates a value from an iterator. Read more
Creates a value from an iterator. Read more
Creates a value from an iterator. Read more
Creates a value from an iterator. Read more
Creates a value from an iterator. Read more
Creates a value from an iterator. Read more
Creates a value from an iterator. Read more
Creates a value from an iterator. Read more
Creates a value from an iterator. Read more
Creates a value from an iterator. Read more
Creates a value from an iterator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl<'a, T: ?Sized> RefUnwindSafe for Cow<'a, T> where
<T as Dairy<'a>>::Cow: RefUnwindSafe,
impl<'a, T: ?Sized> UnwindSafe for Cow<'a, T> where
<T as Dairy<'a>>::Cow: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more