1
Fork 0

Fix doc nits

Many tiny changes to stdlib doc comments to make them consistent (for example
"Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph
breaks, backticks for monospace style, and other minor nits.

https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
This commit is contained in:
John Arundel 2024-07-15 12:26:30 +01:00
parent 83d67685ac
commit a19472a93e
146 changed files with 808 additions and 738 deletions

View file

@ -2,6 +2,7 @@ use crate::io::{self, BufWriter, IoSlice, Write};
use core::slice::memchr;
/// Private helper struct for implementing the line-buffered writing logic.
///
/// This shim temporarily wraps a BufWriter, and uses its internals to
/// implement a line-buffered writer (specifically by using the internal
/// methods like write_to_buf and flush_buf). In this way, a more
@ -20,27 +21,27 @@ impl<'a, W: ?Sized + Write> LineWriterShim<'a, W> {
Self { buffer }
}
/// Get a reference to the inner writer (that is, the writer
/// Gets a reference to the inner writer (that is, the writer
/// wrapped by the BufWriter).
fn inner(&self) -> &W {
self.buffer.get_ref()
}
/// Get a mutable reference to the inner writer (that is, the writer
/// Gets a mutable reference to the inner writer (that is, the writer
/// wrapped by the BufWriter). Be careful with this writer, as writes to
/// it will bypass the buffer.
fn inner_mut(&mut self) -> &mut W {
self.buffer.get_mut()
}
/// Get the content currently buffered in self.buffer
/// Gets the content currently buffered in self.buffer
fn buffered(&self) -> &[u8] {
self.buffer.buffer()
}
/// Flush the buffer iff the last byte is a newline (indicating that an
/// Flushes the buffer iff the last byte is a newline (indicating that an
/// earlier write only succeeded partially, and we want to retry flushing
/// the buffered line before continuing with a subsequent write)
/// the buffered line before continuing with a subsequent write).
fn flush_if_completed_line(&mut self) -> io::Result<()> {
match self.buffered().last().copied() {
Some(b'\n') => self.buffer.flush_buf(),
@ -50,10 +51,11 @@ impl<'a, W: ?Sized + Write> LineWriterShim<'a, W> {
}
impl<'a, W: ?Sized + Write> Write for LineWriterShim<'a, W> {
/// Write some data into this BufReader with line buffering. This means
/// that, if any newlines are present in the data, the data up to the last
/// newline is sent directly to the underlying writer, and data after it
/// is buffered. Returns the number of bytes written.
/// Writes some data into this BufReader with line buffering.
///
/// This means that, if any newlines are present in the data, the data up to
/// the last newline is sent directly to the underlying writer, and data
/// after it is buffered. Returns the number of bytes written.
///
/// This function operates on a "best effort basis"; in keeping with the
/// convention of `Write::write`, it makes at most one attempt to write
@ -136,11 +138,12 @@ impl<'a, W: ?Sized + Write> Write for LineWriterShim<'a, W> {
self.buffer.flush()
}
/// Write some vectored data into this BufReader with line buffering. This
/// means that, if any newlines are present in the data, the data up to
/// and including the buffer containing the last newline is sent directly
/// to the inner writer, and the data after it is buffered. Returns the
/// number of bytes written.
/// Writes some vectored data into this BufReader with line buffering.
///
/// This means that, if any newlines are present in the data, the data up to
/// and including the buffer containing the last newline is sent directly to
/// the inner writer, and the data after it is buffered. Returns the number
/// of bytes written.
///
/// This function operates on a "best effort basis"; in keeping with the
/// convention of `Write::write`, it makes at most one attempt to write
@ -245,10 +248,11 @@ impl<'a, W: ?Sized + Write> Write for LineWriterShim<'a, W> {
self.inner().is_write_vectored()
}
/// Write some data into this BufReader with line buffering. This means
/// that, if any newlines are present in the data, the data up to the last
/// newline is sent directly to the underlying writer, and data after it
/// is buffered.
/// Writes some data into this BufReader with line buffering.
///
/// This means that, if any newlines are present in the data, the data up to
/// the last newline is sent directly to the underlying writer, and data
/// after it is buffered.
///
/// Because this function attempts to send completed lines to the underlying
/// writer, it will also flush the existing buffer if it contains any

View file

@ -48,7 +48,7 @@ pub use bufwriter::WriterPanicked;
pub struct IntoInnerError<W>(W, Error);
impl<W> IntoInnerError<W> {
/// Construct a new IntoInnerError
/// Constructs a new IntoInnerError
fn new(writer: W, error: Error) -> Self {
Self(writer, error)
}

View file

@ -167,7 +167,7 @@ impl SimpleMessage {
}
}
/// Create and return an `io::Error` for a given `ErrorKind` and constant
/// Creates and returns an `io::Error` for a given `ErrorKind` and constant
/// message. This doesn't allocate.
pub(crate) macro const_io_error($kind:expr, $message:expr $(,)?) {
$crate::io::error::Error::from_static_message({
@ -852,7 +852,7 @@ impl Error {
}
}
/// Attempt to downcast the custom boxed error to `E`.
/// Attempts to downcast the custom boxed error to `E`.
///
/// If this [`Error`] contains a custom boxed error,
/// then it would attempt downcasting on the boxed error,

View file

@ -782,7 +782,7 @@ pub trait Read {
false
}
/// Read all bytes until EOF in this source, placing them into `buf`.
/// Reads all bytes until EOF in this source, placing them into `buf`.
///
/// All bytes read from this source will be appended to the specified buffer
/// `buf`. This function will continuously call [`read()`] to append more data to
@ -866,7 +866,7 @@ pub trait Read {
default_read_to_end(self, buf, None)
}
/// Read all bytes until EOF in this source, appending them to `buf`.
/// Reads all bytes until EOF in this source, appending them to `buf`.
///
/// If successful, this function returns the number of bytes which were read
/// and appended to `buf`.
@ -909,7 +909,7 @@ pub trait Read {
default_read_to_string(self, buf, None)
}
/// Read the exact number of bytes required to fill `buf`.
/// Reads the exact number of bytes required to fill `buf`.
///
/// This function reads as many bytes as necessary to completely fill the
/// specified buffer `buf`.
@ -973,7 +973,7 @@ pub trait Read {
default_read_buf(|b| self.read(b), buf)
}
/// Read the exact number of bytes required to fill `cursor`.
/// Reads the exact number of bytes required to fill `cursor`.
///
/// This is similar to the [`read_exact`](Read::read_exact) method, except
/// that it is passed a [`BorrowedCursor`] rather than `[u8]` to allow use
@ -1159,7 +1159,7 @@ pub trait Read {
}
}
/// Read all bytes from a [reader][Read] into a new [`String`].
/// Reads all bytes from a [reader][Read] into a new [`String`].
///
/// This is a convenience function for [`Read::read_to_string`]. Using this
/// function avoids having to create a variable first and provides more type
@ -1212,7 +1212,7 @@ pub fn read_to_string<R: Read>(mut reader: R) -> Result<String> {
/// A buffer type used with `Read::read_vectored`.
///
/// It is semantically a wrapper around an `&mut [u8]`, but is guaranteed to be
/// It is semantically a wrapper around a `&mut [u8]`, but is guaranteed to be
/// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on
/// Windows.
#[stable(feature = "iovec", since = "1.36.0")]
@ -1531,7 +1531,7 @@ impl<'a> Deref for IoSlice<'a> {
#[doc(notable_trait)]
#[cfg_attr(not(test), rustc_diagnostic_item = "IoWrite")]
pub trait Write {
/// Write a buffer into this writer, returning how many bytes were written.
/// Writes a buffer into this writer, returning how many bytes were written.
///
/// This function will attempt to write the entire contents of `buf`, but
/// the entire write might not succeed, or the write may also generate an
@ -1630,7 +1630,7 @@ pub trait Write {
false
}
/// Flush this output stream, ensuring that all intermediately buffered
/// Flushes this output stream, ensuring that all intermediately buffered
/// contents reach their destination.
///
/// # Errors
@ -2247,7 +2247,7 @@ pub trait BufRead: Read {
#[stable(feature = "rust1", since = "1.0.0")]
fn consume(&mut self, amt: usize);
/// Check if the underlying `Read` has any data left to be read.
/// Checks if the underlying `Read` has any data left to be read.
///
/// This function may fill the buffer to check for data,
/// so this functions returns `Result<bool>`, not `bool`.
@ -2278,7 +2278,7 @@ pub trait BufRead: Read {
self.fill_buf().map(|b| !b.is_empty())
}
/// Read all bytes into `buf` until the delimiter `byte` or EOF is reached.
/// Reads all bytes into `buf` until the delimiter `byte` or EOF is reached.
///
/// This function will read bytes from the underlying stream until the
/// delimiter or EOF is found. Once found, all bytes up to, and including,
@ -2337,7 +2337,7 @@ pub trait BufRead: Read {
read_until(self, byte, buf)
}
/// Skip all bytes until the delimiter `byte` or EOF is reached.
/// Skips all bytes until the delimiter `byte` or EOF is reached.
///
/// This function will read (and discard) bytes from the underlying stream until the
/// delimiter or EOF is found.
@ -2399,7 +2399,7 @@ pub trait BufRead: Read {
skip_until(self, byte)
}
/// Read all bytes until a newline (the `0xA` byte) is reached, and append
/// Reads all bytes until a newline (the `0xA` byte) is reached, and append
/// them to the provided `String` buffer.
///
/// Previous content of the buffer will be preserved. To avoid appending to
@ -3038,7 +3038,7 @@ where
}
}
/// Read a single byte in a slow, generic way. This is used by the default
/// Reads a single byte in a slow, generic way. This is used by the default
/// `spec_read_byte`.
#[inline]
fn inlined_slow_read_byte<R: Read>(reader: &mut R) -> Option<Result<u8>> {

View file

@ -1092,7 +1092,7 @@ pub fn try_set_output_capture(
OUTPUT_CAPTURE.try_with(move |slot| slot.replace(sink))
}
/// Write `args` to the capture buffer if enabled and possible, or `global_s`
/// Writes `args` to the capture buffer if enabled and possible, or `global_s`
/// otherwise. `label` identifies the stream in a panic message.
///
/// This function is used to print error messages, so it takes extra

View file

@ -530,7 +530,7 @@ fn io_slice_advance_slices_beyond_total_length() {
assert!(bufs.is_empty());
}
/// Create a new writer that reads from at most `n_bufs` and reads
/// Creates a new writer that reads from at most `n_bufs` and reads
/// `per_call` bytes (in total) per call to write.
fn test_writer(n_bufs: usize, per_call: usize) -> TestWriter {
TestWriter { n_bufs, per_call, written: Vec::new() }