Skip to content

Commit 9568f44

Browse files
committed
Add documentation for Read, Write impls for slices and Vec
The Write impls for &[u8] and Vec<u8> are quite different, and we need this to be reflected in the docs. These documentation comments will be visible on the respective type's page in the trait impls section.
1 parent 7bccb82 commit 9568f44

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/libstd/io/impls.rs

+11
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ impl<B: BufRead + ?Sized> BufRead for Box<B> {
147147
// =============================================================================
148148
// In-memory buffer implementations
149149

150+
/// Read is implemented for `&[u8]` by copying from the slice.
151+
///
152+
/// Note that reading updates the slice to point to the yet unread part.
153+
/// The slice will be empty when EOF is reached.
150154
#[stable(feature = "rust1", since = "1.0.0")]
151155
impl<'a> Read for &'a [u8] {
152156
#[inline]
@@ -180,6 +184,11 @@ impl<'a> BufRead for &'a [u8] {
180184
fn consume(&mut self, amt: usize) { *self = &self[amt..]; }
181185
}
182186

187+
/// Write is implemented for `&mut [u8]` by copying into the slice, overwriting
188+
/// its data.
189+
///
190+
/// Note that writing updates the slice to point to the yet unwritten part.
191+
/// The slice will be empty when it has been completely overwritten.
183192
#[stable(feature = "rust1", since = "1.0.0")]
184193
impl<'a> Write for &'a mut [u8] {
185194
#[inline]
@@ -204,6 +213,8 @@ impl<'a> Write for &'a mut [u8] {
204213
fn flush(&mut self) -> io::Result<()> { Ok(()) }
205214
}
206215

216+
/// Write is implemented for `Vec<u8>` by appending to the vector.
217+
/// The vector will grow as needed.
207218
#[stable(feature = "rust1", since = "1.0.0")]
208219
impl Write for Vec<u8> {
209220
#[inline]

0 commit comments

Comments
 (0)