@@ -419,14 +419,8 @@ fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize>
419
419
///
420
420
/// [`File`]s implement `Read`:
421
421
///
422
- /// [`read()`]: trait.Read.html#tymethod.read
423
- /// [`std::io`]: ../../std/io/index.html
424
- /// [`File`]: ../fs/struct.File.html
425
- /// [`BufRead`]: trait.BufRead.html
426
- /// [`BufReader`]: struct.BufReader.html
427
- ///
428
422
/// ```
429
- /// use std::io;
423
+ /// # use std::io;
430
424
/// use std::io::prelude::*;
431
425
/// use std::fs::File;
432
426
///
@@ -449,6 +443,32 @@ fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize>
449
443
/// # Ok(())
450
444
/// # }
451
445
/// ```
446
+ ///
447
+ /// Read from `&str` because [`&[u8]`] implements [`Read`]:
448
+ ///
449
+ /// ```
450
+ /// # use std::io;
451
+ /// use std::io::prelude::*;
452
+ ///
453
+ /// # fn foo() -> io::Result<()> {
454
+ /// let mut b = "This string will be read".as_bytes();
455
+ /// let mut buffer = [0; 10];
456
+ ///
457
+ /// // read up to 10 bytes
458
+ /// b.read(&mut buffer)?;
459
+ ///
460
+ /// // etc... it works exactly as a File does!
461
+ /// # Ok(())
462
+ /// # }
463
+ /// ```
464
+ ///
465
+ /// [`read()`]: trait.Read.html#tymethod.read
466
+ /// [`std::io`]: ../../std/io/index.html
467
+ /// [`File`]: ../fs/struct.File.html
468
+ /// [`BufRead`]: trait.BufRead.html
469
+ /// [`BufReader`]: struct.BufReader.html
470
+ /// [`&[u8]`]: primitive.slice.html
471
+ ///
452
472
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
453
473
pub trait Read {
454
474
/// Pull some bytes from this source into the specified buffer, returning
0 commit comments