From 00e3149dede9fbc464e0f654e7093626d7a8ca27 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Tue, 19 Jul 2016 20:38:35 -0400 Subject: [PATCH] Add doc examples for `Vec::{as_slice,as_mut_slice}`. --- src/libcollections/vec.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 518b94b5031..4cc5b11dc34 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -541,6 +541,14 @@ impl Vec { /// Extracts a slice containing the entire vector. /// /// Equivalent to `&s[..]`. + /// + /// # Examples + /// + /// ``` + /// use std::io::{self, Write}; + /// let buffer = vec![1, 2, 3, 5, 8]; + /// io::sink().write(buffer.as_slice()).unwrap(); + /// ``` #[inline] #[stable(feature = "vec_as_slice", since = "1.7.0")] pub fn as_slice(&self) -> &[T] { @@ -550,6 +558,14 @@ impl Vec { /// Extracts a mutable slice of the entire vector. /// /// Equivalent to `&mut s[..]`. + /// + /// # Examples + /// + /// ``` + /// use std::io::{self, Read}; + /// let mut buffer = vec![0; 3]; + /// io::repeat(0b101).read_exact(buffer.as_mut_slice()).unwrap(); + /// ``` #[inline] #[stable(feature = "vec_as_slice", since = "1.7.0")] pub fn as_mut_slice(&mut self) -> &mut [T] {