diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-07-21 11:27:01 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-07-21 11:27:01 +0200 |
| commit | 1006f794cdb45e28dfdd4a548f8a891ec4023598 (patch) | |
| tree | f13487a6d8a876b261357200b28c7785fa98ec34 /src | |
| parent | 3f3dabb008ffb56fa008771937dc65ce53eda862 (diff) | |
| parent | 00e3149dede9fbc464e0f654e7093626d7a8ca27 (diff) | |
| download | rust-1006f794cdb45e28dfdd4a548f8a891ec4023598.tar.gz rust-1006f794cdb45e28dfdd4a548f8a891ec4023598.zip | |
Rollup merge of #34930 - frewsxcv:vec-as-slice, r=steveklabnik
Add doc examples for `Vec::{as_slice,as_mut_slice}`.
None
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcollections/vec.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 9ca3a5bd607..2d77b38879b 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -541,6 +541,14 @@ impl<T> Vec<T> { /// 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<T> Vec<T> { /// 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] { |
