Skip to content

Commit 3870e8a

Browse files
committed
Document From impls for cow.rs
1 parent 54bdfa1 commit 3870e8a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

library/alloc/src/vec/cow.rs

+18
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,38 @@ use super::Vec;
55

66
#[stable(feature = "cow_from_vec", since = "1.8.0")]
77
impl<'a, T: Clone> From<&'a [T]> for Cow<'a, [T]> {
8+
/// Creates a [`Borrowed`] variant of [`Cow`]
9+
/// from a slice.
10+
///
11+
/// This conversion does not allocate or clone the data.
12+
///
13+
/// [`Borrowed`]: crate::borrow::Cow::Borrowed
814
fn from(s: &'a [T]) -> Cow<'a, [T]> {
915
Cow::Borrowed(s)
1016
}
1117
}
1218

1319
#[stable(feature = "cow_from_vec", since = "1.8.0")]
1420
impl<'a, T: Clone> From<Vec<T>> for Cow<'a, [T]> {
21+
/// Creates an [`Owned`] variant of [`Cow`]
22+
/// from an owned instance of [`Vec`].
23+
///
24+
/// This conversion does not allocate or clone the data.
25+
///
26+
/// [`Owned`]: crate::borrow::Cow::Owned
1527
fn from(v: Vec<T>) -> Cow<'a, [T]> {
1628
Cow::Owned(v)
1729
}
1830
}
1931

2032
#[stable(feature = "cow_from_vec_ref", since = "1.28.0")]
2133
impl<'a, T: Clone> From<&'a Vec<T>> for Cow<'a, [T]> {
34+
/// Creates a [`Borrowed`] variant of [`Cow`]
35+
/// from a reference to [`Vec`].
36+
///
37+
/// This conversion does not allocate or clone the data.
38+
///
39+
/// [`Borrowed`]: crate::borrow::Cow::Borrowed
2240
fn from(v: &'a Vec<T>) -> Cow<'a, [T]> {
2341
Cow::Borrowed(v.as_slice())
2442
}

0 commit comments

Comments
 (0)