Add doc for Read
ing from &str
and some related cleanup
This commit is contained in:
parent
b1409af73d
commit
44da4a0656
1 changed files with 27 additions and 7 deletions
|
@ -419,14 +419,8 @@ fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize>
|
||||||
///
|
///
|
||||||
/// [`File`]s implement `Read`:
|
/// [`File`]s implement `Read`:
|
||||||
///
|
///
|
||||||
/// [`read()`]: trait.Read.html#tymethod.read
|
|
||||||
/// [`std::io`]: ../../std/io/index.html
|
|
||||||
/// [`File`]: ../fs/struct.File.html
|
|
||||||
/// [`BufRead`]: trait.BufRead.html
|
|
||||||
/// [`BufReader`]: struct.BufReader.html
|
|
||||||
///
|
|
||||||
/// ```
|
/// ```
|
||||||
/// use std::io;
|
/// # use std::io;
|
||||||
/// use std::io::prelude::*;
|
/// use std::io::prelude::*;
|
||||||
/// use std::fs::File;
|
/// use std::fs::File;
|
||||||
///
|
///
|
||||||
|
@ -449,6 +443,32 @@ fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize>
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// Read from `&str` because [`&[u8]`] implements [`Read`]:
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use std::io;
|
||||||
|
/// use std::io::prelude::*;
|
||||||
|
///
|
||||||
|
/// # fn foo() -> io::Result<()> {
|
||||||
|
/// let mut b = "This string will be read".as_bytes();
|
||||||
|
/// let mut buffer = [0; 10];
|
||||||
|
///
|
||||||
|
/// // read up to 10 bytes
|
||||||
|
/// b.read(&mut buffer)?;
|
||||||
|
///
|
||||||
|
/// // etc... it works exactly as a File does!
|
||||||
|
/// # Ok(())
|
||||||
|
/// # }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// [`read()`]: trait.Read.html#tymethod.read
|
||||||
|
/// [`std::io`]: ../../std/io/index.html
|
||||||
|
/// [`File`]: ../fs/struct.File.html
|
||||||
|
/// [`BufRead`]: trait.BufRead.html
|
||||||
|
/// [`BufReader`]: struct.BufReader.html
|
||||||
|
/// [`&[u8]`]: primitive.slice.html
|
||||||
|
///
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub trait Read {
|
pub trait Read {
|
||||||
/// Pull some bytes from this source into the specified buffer, returning
|
/// Pull some bytes from this source into the specified buffer, returning
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue