]> git.lizzy.rs Git - rust.git/blobdiff - src/libcollections/vec.rs
Rollup merge of #34930 - frewsxcv:vec-as-slice, r=steveklabnik
[rust.git] / src / libcollections / vec.rs
index 9ca3a5bd6079ad7a7c020a3520a323d466abf4c6..2d77b38879b8eb8a959f4920b51abbf6bc66f57c 100644 (file)
@@ -541,6 +541,14 @@ pub fn truncate(&mut self, len: usize) {
     /// 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 @@ pub fn as_slice(&self) -> &[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] {