mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 07:22:42 +00:00
Add doc examples for Vec::{as_slice,as_mut_slice}
.
This commit is contained in:
parent
27e766d7bc
commit
00e3149ded
@ -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] {
|
||||
|
Loading…
Reference in New Issue
Block a user