Skip to content

Commit 00e3149

Browse files
committed
Add doc examples for Vec::{as_slice,as_mut_slice}.
1 parent 27e766d commit 00e3149

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/libcollections/vec.rs

+16
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,14 @@ impl<T> Vec<T> {
541541
/// Extracts a slice containing the entire vector.
542542
///
543543
/// Equivalent to `&s[..]`.
544+
///
545+
/// # Examples
546+
///
547+
/// ```
548+
/// use std::io::{self, Write};
549+
/// let buffer = vec![1, 2, 3, 5, 8];
550+
/// io::sink().write(buffer.as_slice()).unwrap();
551+
/// ```
544552
#[inline]
545553
#[stable(feature = "vec_as_slice", since = "1.7.0")]
546554
pub fn as_slice(&self) -> &[T] {
@@ -550,6 +558,14 @@ impl<T> Vec<T> {
550558
/// Extracts a mutable slice of the entire vector.
551559
///
552560
/// Equivalent to `&mut s[..]`.
561+
///
562+
/// # Examples
563+
///
564+
/// ```
565+
/// use std::io::{self, Read};
566+
/// let mut buffer = vec![0; 3];
567+
/// io::repeat(0b101).read_exact(buffer.as_mut_slice()).unwrap();
568+
/// ```
553569
#[inline]
554570
#[stable(feature = "vec_as_slice", since = "1.7.0")]
555571
pub fn as_mut_slice(&mut self) -> &mut [T] {

0 commit comments

Comments
 (0)