about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2016-07-19 20:38:35 -0400
committerCorey Farwell <coreyf@rwell.org>2016-07-19 21:34:45 -0400
commit00e3149dede9fbc464e0f654e7093626d7a8ca27 (patch)
tree8ae6b918ac056fe1ac47b183549679aa2223d4bb
parent27e766d7bc84be992c8ddef710affc92ef4a0adf (diff)
Add doc examples for `Vec::{as_slice,as_mut_slice}`.
-rw-r--r--src/libcollections/vec.rs16
1 files changed, 16 insertions, 0 deletions
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<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] {