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. The type is designed to
work with general borrowed data via the Borrow
trait.
Cow
implements Deref
, which means that you can call
non-mutating methods directly on the data it encloses. If mutation
is desired, to_mut
will obtain a mutable reference to an owned
value, cloning if necessary.
use std::borrow::Cow;
fn abs_all(input: &mut Cow<[i32]>) {
for i in 0..input.len() {
let v = input[i];
if v < 0 {
input.to_mut()[i] = -v;
}
}
}
let slice = [0, 1, 2];
let mut input = Cow::from(&slice[..]);
abs_all(&mut input);
let slice = [-1, 0, 1];
let mut input = Cow::from(&slice[..]);
abs_all(&mut input);
let mut input = Cow::from(vec![-1, 0, 1]);
abs_all(&mut input);Run
Acquires a mutable reference to the owned form of the data.
Clones the data if it is not already owned.
use std::borrow::Cow;
let mut cow = Cow::Borrowed("foo");
cow.to_mut().make_ascii_uppercase();
assert_eq!(
cow,
Cow::Owned(String::from("FOO")) as Cow<str>
);Run
Extracts the owned data.
Clones the data if it is not already owned.
Calling into_owned
on a Cow::Borrowed
clones the underlying data
and becomes a Cow::Owned
:
use std::borrow::Cow;
let s = "Hello world!";
let cow = Cow::Borrowed(s);
assert_eq!(
cow.into_owned(),
String::from(s)
);Run
Calling into_owned
on a Cow::Owned
is a no-op:
use std::borrow::Cow;
let s = "Hello world!";
let cow: Cow<str> = Cow::Owned(String::from(s));
assert_eq!(
cow.into_owned(),
String::from(s)
);Run
Immutably borrows from an owned value. Read more
[+]
[+]
[−]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self | 1.21.0 [src] |
[−]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self | 1.21.0 [src] |
[−]
Compares and returns the minimum of two values. Read more
[+]
[+]
[+]
[+]
[+]
[+]
[+]
[+]
[+]
[+]
[−]
Performs the +=
operation.
[+]
[−]
Performs the +=
operation.
[+]
[−]
Creates an owned Cow<'a, B> with the default value for the contained owned value.
[+]
type Target = B
The resulting type after dereferencing.
[−]
[+]
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
Extends a collection with the contents of an iterator. Read more
[+]
type Output = Cow<'a, str>
The resulting type after applying the +
operator.
[−]
Performs the +
operation.
[+]
type Output = Cow<'a, str>
The resulting type after applying the +
operator.
[−]
Performs the +
operation.
[+]
[−]
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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
[+]
[+]
[+]
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. 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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. 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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. 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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
[+]
[+]
[+]
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. 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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. 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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. 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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. 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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. 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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. 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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. 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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. 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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
[−]
This method tests for !=
.
[+]
[−]
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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. 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
[−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more