Skip to content

Commit 5b096c6

Browse files
author
Ulrik Sverdrup
committed
collections: Add documentation example for as_vec
1 parent 42f7af5 commit 5b096c6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/libcollections/vec.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,6 +1919,22 @@ impl<'a, T> Drop for DerefVec<'a, T> {
19191919
}
19201920

19211921
/// Converts a slice to a wrapper type providing a `&Vec<T>` reference.
1922+
///
1923+
/// # Examples
1924+
///
1925+
/// ```
1926+
/// # #![feature(collections)]
1927+
/// use std::vec::as_vec;
1928+
///
1929+
/// // Let's pretend we have a function that requires &Vec<i32>
1930+
/// fn vec_consumer(s: &Vec<i32>) {
1931+
/// assert_eq!(s, &[1, 2, 3]);
1932+
/// }
1933+
///
1934+
/// // Provide a &Vec<T> from a &[T] without allocating
1935+
/// let values = [1, 2, 3];
1936+
/// vec_consumer(&as_vec(&values));
1937+
/// ```
19221938
#[unstable(feature = "collections")]
19231939
pub fn as_vec<'a, T>(x: &'a [T]) -> DerefVec<'a, T> {
19241940
unsafe {

0 commit comments

Comments
 (0)