Skip to content

Commit

Permalink
document write_fmt length trick for slice
Browse files Browse the repository at this point in the history
  • Loading branch information
MabezDev committed Sep 18, 2023
1 parent b4dfac9 commit 02c22b9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions embedded-io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,15 @@ pub trait Write: ErrorType {
/// If you are using [`WriteReady`] to avoid blocking, you should not use this function.
/// `WriteReady::write_ready()` returning true only guarantees the first call to `write()` will
/// not block, so this function may still block in subsequent calls.
///
/// Unlike [`Write::write`], the number of bytes written is not returned. However, in the case of
/// writing to an `&mut [u8]` its possible to calculate the number of bytes written by subtracting
/// the length of the slice after the write, from the initial length of the slice.
///
/// ```rust
/// let start = buf.len();
/// let len = write!(buf, "{}", DisplayType).and_then(|_| Ok(start - buf.len()));
/// ```
fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> Result<(), WriteFmtError<Self::Error>> {
// Create a shim which translates a Write to a fmt::Write and saves
// off I/O errors. instead of discarding them
Expand Down

0 comments on commit 02c22b9

Please sign in to comment.