Document From
impls for cow.rs
This commit is contained in:
parent
54bdfa1257
commit
3870e8a31d
1 changed files with 18 additions and 0 deletions
|
@ -5,6 +5,12 @@ use super::Vec;
|
|||
|
||||
#[stable(feature = "cow_from_vec", since = "1.8.0")]
|
||||
impl<'a, T: Clone> From<&'a [T]> for Cow<'a, [T]> {
|
||||
/// Creates a [`Borrowed`] variant of [`Cow`]
|
||||
/// from a slice.
|
||||
///
|
||||
/// This conversion does not allocate or clone the data.
|
||||
///
|
||||
/// [`Borrowed`]: crate::borrow::Cow::Borrowed
|
||||
fn from(s: &'a [T]) -> Cow<'a, [T]> {
|
||||
Cow::Borrowed(s)
|
||||
}
|
||||
|
@ -12,6 +18,12 @@ impl<'a, T: Clone> From<&'a [T]> for Cow<'a, [T]> {
|
|||
|
||||
#[stable(feature = "cow_from_vec", since = "1.8.0")]
|
||||
impl<'a, T: Clone> From<Vec<T>> for Cow<'a, [T]> {
|
||||
/// Creates an [`Owned`] variant of [`Cow`]
|
||||
/// from an owned instance of [`Vec`].
|
||||
///
|
||||
/// This conversion does not allocate or clone the data.
|
||||
///
|
||||
/// [`Owned`]: crate::borrow::Cow::Owned
|
||||
fn from(v: Vec<T>) -> Cow<'a, [T]> {
|
||||
Cow::Owned(v)
|
||||
}
|
||||
|
@ -19,6 +31,12 @@ impl<'a, T: Clone> From<Vec<T>> for Cow<'a, [T]> {
|
|||
|
||||
#[stable(feature = "cow_from_vec_ref", since = "1.28.0")]
|
||||
impl<'a, T: Clone> From<&'a Vec<T>> for Cow<'a, [T]> {
|
||||
/// Creates a [`Borrowed`] variant of [`Cow`]
|
||||
/// from a reference to [`Vec`].
|
||||
///
|
||||
/// This conversion does not allocate or clone the data.
|
||||
///
|
||||
/// [`Borrowed`]: crate::borrow::Cow::Borrowed
|
||||
fn from(v: &'a Vec<T>) -> Cow<'a, [T]> {
|
||||
Cow::Borrowed(v.as_slice())
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue