@@ -15,7 +15,7 @@ mod impls;
15
15
16
16
/// Enumeration of possible methods to seek within an I/O object.
17
17
///
18
- /// Semantics are the same as [`std::io::SeekFrom`], check its documentation for details .
18
+ /// This is the `embedded-io` equivalent of [`std::io::SeekFrom`].
19
19
#[ derive( Debug , Copy , Clone , Eq , PartialEq ) ]
20
20
pub enum SeekFrom {
21
21
/// Sets the offset to the provided number of bytes.
@@ -149,12 +149,33 @@ impl<E: fmt::Debug> std::error::Error for WriteAllError<E> {}
149
149
150
150
/// Blocking reader.
151
151
///
152
- /// Semantics are the same as [`std::io::Read`], check its documentation for details .
152
+ /// This trait is the `embedded-io` equivalent of [`std::io::Read`].
153
153
pub trait Read : crate :: ErrorType {
154
- /// Pull some bytes from this source into the specified buffer, returning how many bytes were read.
154
+ /// Read some bytes from this source into the specified buffer, returning how many bytes were read.
155
+ ///
156
+ /// If no bytes are currently available to read, this function blocks until at least one byte is available.
157
+ ///
158
+ /// If bytes are available, a non-zero amount of bytes is read to the beginning of `buf`, and the amount
159
+ /// is returned. It is not guaranteed that *all* available bytes are returned, it is possible for the
160
+ /// implementation to read an amount of bytes less than `buf.len()` while there are more bytes immediately
161
+ /// available.
162
+ ///
163
+ /// If the reader is at end-of-file (EOF), `Ok(0)` is returned. There is no guarantee that a reader at EOF
164
+ /// will always be so in the future, for example a reader can stop being at EOF if another process appends
165
+ /// more bytes to the underlying file.
166
+ ///
167
+ /// If `buf.len() == 0`, `read` returns without blocking, with either `Ok(0)` or an error.
168
+ /// The `Ok(0)` doesn't indicate EOF, unlike when called with a non-empty buffer.
155
169
fn read ( & mut self , buf : & mut [ u8 ] ) -> Result < usize , Self :: Error > ;
156
170
157
171
/// Read the exact number of bytes required to fill `buf`.
172
+ ///
173
+ /// This function calls `read()` in a loop until exactly `buf.len()` bytes have
174
+ /// been read, blocking if needed.
175
+ ///
176
+ /// If you are using [`ReadReady`] to avoid blocking, you should not use this function.
177
+ /// `ReadReady::read_ready()` returning true only guarantees the first call to `read()` will
178
+ /// not block, so this function may still block in subsequent calls.
158
179
fn read_exact ( & mut self , mut buf : & mut [ u8 ] ) -> Result < ( ) , ReadExactError < Self :: Error > > {
159
180
while !buf. is_empty ( ) {
160
181
match self . read ( buf) {
@@ -173,9 +194,15 @@ pub trait Read: crate::ErrorType {
173
194
174
195
/// Blocking buffered reader.
175
196
///
176
- /// Semantics are the same as [`std::io::BufRead`], check its documentation for details .
197
+ /// This trait is the `embedded-io` equivalent of [`std::io::BufRead`].
177
198
pub trait BufRead : crate :: ErrorType {
178
199
/// Return the contents of the internal buffer, filling it with more data from the inner reader if it is empty.
200
+ ///
201
+ /// If no bytes are currently available to read, this function blocks until at least one byte is available.
202
+ ///
203
+ /// If the reader is at end-of-file (EOF), an empty slice is returned. There is no guarantee that a reader at EOF
204
+ /// will always be so in the future, for example a reader can stop being at EOF if another process appends
205
+ /// more bytes to the underlying file.
179
206
fn fill_buf ( & mut self ) -> Result < & [ u8 ] , Self :: Error > ;
180
207
181
208
/// Tell this buffer that `amt` bytes have been consumed from the buffer, so they should no longer be returned in calls to `fill_buf`.
@@ -184,15 +211,36 @@ pub trait BufRead: crate::ErrorType {
184
211
185
212
/// Blocking writer.
186
213
///
187
- /// Semantics are the same as [`std::io::Write`], check its documentation for details .
214
+ /// This trait is the `embedded-io` equivalent of [`std::io::Write`].
188
215
pub trait Write : crate :: ErrorType {
189
216
/// Write a buffer into this writer, returning how many bytes were written.
217
+ ///
218
+ /// If the writer is not currently ready to accept more bytes (for example, its buffer is full),
219
+ /// this function blocks until it is ready to accept least one byte.
220
+ ///
221
+ /// If it's ready to accept bytes, a non-zero amount of bytes is written from the beginning of `buf`, and the amount
222
+ /// is returned. It is not guaranteed that *all* available buffer space is filled, i.e. it is possible for the
223
+ /// implementation to write an amount of bytes less than `buf.len()` while the writer continues to be
224
+ /// ready to accept more bytes immediately.
225
+ ///
226
+ /// Implementations should never return `Ok(0)` when `buf.len() != 0`. Situations where the writer is not
227
+ /// able to accept more bytes and likely never will are better indicated with errors.
228
+ ///
229
+ /// If `buf.len() == 0`, `write` returns without blocking, with either `Ok(0)` or an error.
230
+ /// The `Ok(0)` doesn't indicate an error.
190
231
fn write ( & mut self , buf : & [ u8 ] ) -> Result < usize , Self :: Error > ;
191
232
192
- /// Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
233
+ /// Flush this output stream, blocking until all intermediately buffered contents reach their destination.
193
234
fn flush ( & mut self ) -> Result < ( ) , Self :: Error > ;
194
235
195
236
/// Write an entire buffer into this writer.
237
+ ///
238
+ /// This function calls `write()` in a loop until exactly `buf.len()` bytes have
239
+ /// been written, blocking if needed.
240
+ ///
241
+ /// If you are using [`WriteReady`] to avoid blocking, you should not use this function.
242
+ /// `WriteReady::write_ready()` returning true only guarantees the first call to `write()` will
243
+ /// not block, so this function may still block in subsequent calls.
196
244
fn write_all ( & mut self , mut buf : & [ u8 ] ) -> Result < ( ) , WriteAllError < Self :: Error > > {
197
245
while !buf. is_empty ( ) {
198
246
match self . write ( buf) {
@@ -205,6 +253,13 @@ pub trait Write: crate::ErrorType {
205
253
}
206
254
207
255
/// Write a formatted string into this writer, returning any error encountered.
256
+ ///
257
+ /// This function calls `write()` in a loop until the entire formatted string has
258
+ /// been written, blocking if needed.
259
+ ///
260
+ /// If you are using [`WriteReady`] to avoid blocking, you should not use this function.
261
+ /// `WriteReady::write_ready()` returning true only guarantees the first call to `write()` will
262
+ /// not block, so this function may still block in subsequent calls.
208
263
fn write_fmt ( & mut self , fmt : fmt:: Arguments < ' _ > ) -> Result < ( ) , WriteFmtError < Self :: Error > > {
209
264
// Create a shim which translates a Write to a fmt::Write and saves
210
265
// off I/O errors. instead of discarding them
@@ -245,7 +300,7 @@ pub trait Write: crate::ErrorType {
245
300
246
301
/// Blocking seek within streams.
247
302
///
248
- /// Semantics are the same as [`std::io::Seek`], check its documentation for details .
303
+ /// This trait is the `embedded-io` equivalent of [`std::io::Seek`].
249
304
pub trait Seek : crate :: ErrorType {
250
305
/// Seek to an offset, in bytes, in a stream.
251
306
fn seek ( & mut self , pos : crate :: SeekFrom ) -> Result < u64 , Self :: Error > ;
0 commit comments