@@ -19,28 +19,30 @@ pub use embedded_io::{
1919pub trait Read : ErrorType {
2020 /// Read some bytes from this source into the specified buffer, returning how many bytes were read.
2121 ///
22- /// If no bytes are currently available to read, this function waits until at least one byte is available.
23- ///
24- /// If bytes are available, a non-zero amount of bytes is read to the beginning of `buf`, and the amount
25- /// is returned. It is not guaranteed that *all* available bytes are returned, it is possible for the
26- /// implementation to read an amount of bytes less than `buf.len()` while there are more bytes immediately
27- /// available.
22+ /// If no bytes are currently available to read:
23+ /// - The method waits until at least one byte becomes available;
24+ /// - Once at least one (or more) bytes become available, a non-zero amount of those is copied to the
25+ /// beginning of `buf`, and the amount is returned, *without waiting any further for more bytes to
26+ /// become available*.
27+ ///
28+ /// If bytes are available to read:
29+ /// - A non-zero amount of bytes is read to the beginning of `buf`, and the amount is returned immediately,
30+ /// *without waiting for more bytes to become available*;
31+ /// - It is not guaranteed that *all* available bytes are returned, it is possible for the implementation to
32+ /// read an amount of bytes less than `buf.len()` while there are more bytes immediately available.
33+ ///
34+ /// This waiting behavior is important for the cases where `Read` represents the "read" leg of a pipe-like
35+ /// protocol (a socket, a pipe, a serial line etc.). The semantics is that the caller - by passing a non-empty
36+ /// buffer - does expect _some_ data (one or more bytes) - but _not necessarily `buf.len()` or more bytes_ -
37+ /// to become available, before the peer represented by `Read` would stop sending bytes due to
38+ /// application-specific reasons (as in the peer waiting for a response to the data it had sent so far).
2839 ///
2940 /// If the reader is at end-of-file (EOF), `Ok(0)` is returned. There is no guarantee that a reader at EOF
3041 /// will always be so in the future, for example a reader can stop being at EOF if another process appends
3142 /// more bytes to the underlying file.
3243 ///
3344 /// If `buf.len() == 0`, `read` returns without waiting, with either `Ok(0)` or an error.
3445 /// The `Ok(0)` doesn't indicate EOF, unlike when called with a non-empty buffer.
35- ///
36- /// Implementations are encouraged to make this function side-effect-free on cancel (AKA "cancel-safe"), i.e.
37- /// guarantee that if you cancel (drop) a `read()` future that hasn't completed yet, the stream's
38- /// state hasn't changed (no bytes have been read).
39- ///
40- /// This is not a requirement to allow implementations that read into the user's buffer straight from
41- /// the hardware with e.g. DMA.
42- ///
43- /// Implementations should document whether they're actually side-effect-free on cancel or not.
4446 async fn read ( & mut self , buf : & mut [ u8 ] ) -> Result < usize , Self :: Error > ;
4547
4648 /// Read the exact number of bytes required to fill `buf`.
0 commit comments