File tree 1 file changed +11
-0
lines changed
1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -401,6 +401,17 @@ pub trait Write: ErrorType {
401
401
/// If you are using [`WriteReady`] to avoid blocking, you should not use this function.
402
402
/// `WriteReady::write_ready()` returning true only guarantees the first call to `write()` will
403
403
/// not block, so this function may still block in subsequent calls.
404
+ ///
405
+ /// Unlike [`Write::write`], the number of bytes written is not returned. However, in the case of
406
+ /// writing to an `&mut [u8]` its possible to calculate the number of bytes written by subtracting
407
+ /// the length of the slice after the write, from the initial length of the slice.
408
+ ///
409
+ /// ```rust
410
+ /// # use embedded_io::Write;
411
+ /// let mut buf: &mut [u8] = &mut [0u8; 256];
412
+ /// let start = buf.len();
413
+ /// let len = write!(buf, "{}", "Test").and_then(|_| Ok(start - buf.len()));
414
+ /// ```
404
415
fn write_fmt ( & mut self , fmt : fmt:: Arguments < ' _ > ) -> Result < ( ) , WriteFmtError < Self :: Error > > {
405
416
// Create a shim which translates a Write to a fmt::Write and saves
406
417
// off I/O errors. instead of discarding them
You can’t perform that action at this time.
0 commit comments