rustc_target ::spec Type Alias StaticCow Copy item path
Summary Source type StaticCow<T> = Cow <'static, T>;
enum StaticCow<T> {
Borrowed(&'static T ),
Owned(<T as ToOwned >::Owned ),
}
Note: Encountered an error during type layout; the type failed to be normalized.
Implementations 🔬 This is a nightly-only experimental API. (cow_is_borrowed
)
Returns true if the data is borrowed, i.e. if to_mut
would require additional work.
§ Examples
#![feature(cow_is_borrowed)]
use std::borrow::Cow;
let cow = Cow::Borrowed("moo" );
assert! (cow.is_borrowed());
let bull: Cow<'_ , str> = Cow::Owned("...moo?" .to_string());
assert! (!bull.is_borrowed());
🔬 This is a nightly-only experimental API. (cow_is_borrowed
)
Returns true if the data is owned, i.e. if to_mut
would be a no-op.
§ Examples
#![feature(cow_is_borrowed)]
use std::borrow::Cow;
let cow: Cow<'_ , str> = Cow::Owned("moo" .to_string());
assert! (cow.is_owned());
let bull = Cow::Borrowed("...moo?" );
assert! (!bull.is_owned());
Acquires a mutable reference to the owned form of the data.
Clones the data if it is not already owned.
§ Examples
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>
);
Extracts the owned data.
Clones the data if it is not already owned.
§ Examples
Calling into_owned
on a Cow::Borrowed
returns a clone of the borrowed data:
use std::borrow::Cow;
let s = "Hello world!" ;
let cow = Cow::Borrowed(s);
assert_eq! (
cow.into_owned(),
String::from(s)
);
Calling into_owned
on a Cow::Owned
returns the owned data. The data is moved out of the
Cow
without being cloned.
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)
);
Trait Implementations The resulting type after applying the +
operator.
The resulting type after applying the +
operator.
Returns a view of this string as a string slice.
Returns a potentially-lossy rendering of this string as a
Cow<'_, str>
.
Returns a view of this string as a maybe-owned
CStr
.
Consumes
self
and returns a view of this string as a maybe-owned
CStr
.
Runs a closure with self
passed in as a &CStr
.
Returns a view of this string as a string slice.
Returns a potentially-lossy rendering of this string as a
Cow<'_, str>
.
Returns a view of this string as a maybe-owned
CStr
.
Consumes
self
and returns a view of this string as a maybe-owned
CStr
.
Runs a closure with self
passed in as a &CStr
.
Returns a view of this string as a string slice.
Returns a potentially-lossy rendering of this string as a
Cow<'_, str>
.
Returns a view of this string as a maybe-owned
CStr
.
Consumes
self
and returns a view of this string as a maybe-owned
CStr
.
Runs a closure with self
passed in as a &CStr
.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Immutably borrows from an owned value.
Read more Performs copy-assignment from
source
.
Read more Formats the value using the given formatter.
Read more Creates an owned Cow<’a, B> with the default value for the contained owned value.
The resulting type after dereferencing.
Dereferences the value.
Deserialize this value from the given Serde deserializer.
Read more Formats the value using the given formatter.
Read more Creates a Borrowed
variant of Cow
from a slice.
This conversion does not allocate or clone the data.
Creates a Borrowed
variant of Cow
from a reference to an array.
This conversion does not allocate or clone the data.
Converts a CStr
into a borrowed Cow
without copying or allocating.
Converts a &
CString
into a borrowed Cow
without copying or allocating.
Creates a clone-on-write pointer from a reference to
Path
.
This conversion does not clone or allocate.
Creates a clone-on-write pointer from a reference to
PathBuf
.
This conversion does not clone or allocate.
Converts a String
reference into a Borrowed
variant.
No heap allocation is performed, and the string
is not copied.
§ Example
let s = "eggplant" .to_string();
assert_eq! (Cow::from(& s), Cow::Borrowed("eggplant" ));
Creates a Borrowed
variant of Cow
from a reference to Vec
.
This conversion does not allocate or clone the data.
Converts a string slice into a Borrowed
variant.
No heap allocation is performed, and the string
is not copied.
§ Example
assert_eq! (Cow::from("eggplant" ), Cow::Borrowed("eggplant" ));
Converts a CString
into an owned Cow
without copying or allocating.
Creates a clone-on-write pointer from an owned
instance of PathBuf
.
This conversion does not clone or allocate.
Converts a String
into an Owned
variant.
No heap allocation is performed, and the string
is not copied.
§ Example
let s = "eggplant" .to_string();
let s2 = "eggplant" .to_string();
assert_eq! (Cow::from(s), Cow::<'static , str>::Owned(s2));
Creates an Owned
variant of Cow
from an owned instance of Vec
.
This conversion does not allocate or clone the data.
Collects an arbitrary Cow
collection.
Note, the standard library only has FromIterator
for Cow<'a, str>
and
Cow<'a, [T]>
, because no one thought to add a blanket implementation
before it was stabilized.
Creates an instance of the collection from the parallel iterator
par_iter
.
Read more The type of the deserializer being converted into.
Convert this value into a deserializer.
Compares and returns the maximum of two values.
Read more Compares and returns the minimum of two values.
Read more Restrict a value to a certain interval.
Read more Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
This method returns an ordering between
self
and
other
values if one exists.
Read more Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more 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 Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more 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 Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more 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 Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more 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 Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more 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 Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more 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 Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more 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 Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more 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 Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more 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 Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more 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 Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more 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 Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more 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 Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self
and
other
) and is used by
the
>=
operator.
Read more Serialize this value into the given Serde serializer.
Read more