@@ -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.
@@ -207,12 +207,33 @@ impl<E: fmt::Debug> std::error::Error for WriteAllError<E> {}
207
207
208
208
/// Blocking reader.
209
209
///
210
- /// Semantics are the same as [`std::io::Read`], check its documentation for details .
210
+ /// This trait is the `embedded-io` equivalent of [`std::io::Read`].
211
211
pub trait Read : crate :: ErrorType {
212
- /// Pull some bytes from this source into the specified buffer, returning how many bytes were read.
212
+ /// Read some bytes from this source into the specified buffer, returning how many bytes were read.
213
+ ///
214
+ /// If no bytes are currently available to read, this function blocks until at least one byte is available.
215
+ ///
216
+ /// If bytes are available, a non-zero amount of bytes is read to the beginning of `buf`, and the amount
217
+ /// is returned. It is not guaranteed that *all* available bytes are returned, it is possible for the
218
+ /// implementation to read an amount of bytes less than `buf.len()` while there are more bytes immediately
219
+ /// available.
220
+ ///
221
+ /// If the reader is at end-of-file (EOF), `Ok(0)` is returned. There is no guarantee that a reader at EOF
222
+ /// will always be so in the future, for example a reader can stop being at EOF if another process appends
223
+ /// more bytes to the underlying file.
224
+ ///
225
+ /// If `buf.len() == 0`, `read` returns without blocking, with either `Ok(0)` or an error.
226
+ /// The `Ok(0)` doesn't indicate EOF, unlike when called with a non-empty buffer.
213
227
fn read ( & mut self , buf : & mut [ u8 ] ) -> Result < usize , Self :: Error > ;
214
228
215
229
/// Read the exact number of bytes required to fill `buf`.
230
+ ///
231
+ /// This function calls `read()` in a loop until exactly `buf.len()` bytes have
232
+ /// been read, blocking if needed.
233
+ ///
234
+ /// If you are using [`ReadReady`] to avoid blocking, you should not use this function.
235
+ /// `ReadReady::read_ready()` returning true only guarantees the first call to `read()` will
236
+ /// not block, so this function may still block in subsequent calls.
216
237
fn read_exact ( & mut self , mut buf : & mut [ u8 ] ) -> Result < ( ) , ReadExactError < Self :: Error > > {
217
238
while !buf. is_empty ( ) {
218
239
match self . read ( buf) {
@@ -231,9 +252,15 @@ pub trait Read: crate::ErrorType {
231
252
232
253
/// Blocking buffered reader.
233
254
///
234
- /// Semantics are the same as [`std::io::BufRead`], check its documentation for details .
255
+ /// This trait is the `embedded-io` equivalent of [`std::io::BufRead`].
235
256
pub trait BufRead : crate :: ErrorType {
236
257
/// Return the contents of the internal buffer, filling it with more data from the inner reader if it is empty.
258
+ ///
259
+ /// If no bytes are currently available to read, this function blocks until at least one byte is available.
260
+ ///
261
+ /// If the reader is at end-of-file (EOF), an empty slice is returned. There is no guarantee that a reader at EOF
262
+ /// will always be so in the future, for example a reader can stop being at EOF if another process appends
263
+ /// more bytes to the underlying file.
237
264
fn fill_buf ( & mut self ) -> Result < & [ u8 ] , Self :: Error > ;
238
265
239
266
/// Tell this buffer that `amt` bytes have been consumed from the buffer, so they should no longer be returned in calls to `fill_buf`.
@@ -242,15 +269,36 @@ pub trait BufRead: crate::ErrorType {
242
269
243
270
/// Blocking writer.
244
271
///
245
- /// Semantics are the same as [`std::io::Write`], check its documentation for details .
272
+ /// This trait is the `embedded-io` equivalent of [`std::io::Write`].
246
273
pub trait Write : crate :: ErrorType {
247
274
/// Write a buffer into this writer, returning how many bytes were written.
275
+ ///
276
+ /// If the writer is not currently ready to accept more bytes (for example, its buffer is full),
277
+ /// this function blocks until it is ready to accept least one byte.
278
+ ///
279
+ /// If it's ready to accept bytes, a non-zero amount of bytes is written from the beginning of `buf`, and the amount
280
+ /// is returned. It is not guaranteed that *all* available buffer space is filled, i.e. it is possible for the
281
+ /// implementation to write an amount of bytes less than `buf.len()` while the writer continues to be
282
+ /// ready to accept more bytes immediately.
283
+ ///
284
+ /// Implementations should never return `Ok(0)` when `buf.len() != 0`. Situations where the writer is not
285
+ /// able to accept more bytes and likely never will are better indicated with errors.
286
+ ///
287
+ /// If `buf.len() == 0`, `write` returns without blocking, with either `Ok(0)` or an error.
288
+ /// The `Ok(0)` doesn't indicate an error.
248
289
fn write ( & mut self , buf : & [ u8 ] ) -> Result < usize , Self :: Error > ;
249
290
250
- /// Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
291
+ /// Flush this output stream, blocking until all intermediately buffered contents reach their destination.
251
292
fn flush ( & mut self ) -> Result < ( ) , Self :: Error > ;
252
293
253
294
/// Write an entire buffer into this writer.
295
+ ///
296
+ /// This function calls `write()` in a loop until exactly `buf.len()` bytes have
297
+ /// been written, blocking if needed.
298
+ ///
299
+ /// If you are using [`WriteReady`] to avoid blocking, you should not use this function.
300
+ /// `WriteReady::write_ready()` returning true only guarantees the first call to `write()` will
301
+ /// not block, so this function may still block in subsequent calls.
254
302
fn write_all ( & mut self , mut buf : & [ u8 ] ) -> Result < ( ) , WriteAllError < Self :: Error > > {
255
303
while !buf. is_empty ( ) {
256
304
match self . write ( buf) {
@@ -263,6 +311,13 @@ pub trait Write: crate::ErrorType {
263
311
}
264
312
265
313
/// Write a formatted string into this writer, returning any error encountered.
314
+ ///
315
+ /// This function calls `write()` in a loop until the entire formatted string has
316
+ /// been written, blocking if needed.
317
+ ///
318
+ /// If you are using [`WriteReady`] to avoid blocking, you should not use this function.
319
+ /// `WriteReady::write_ready()` returning true only guarantees the first call to `write()` will
320
+ /// not block, so this function may still block in subsequent calls.
266
321
fn write_fmt ( & mut self , fmt : fmt:: Arguments < ' _ > ) -> Result < ( ) , WriteFmtError < Self :: Error > > {
267
322
// Create a shim which translates a Write to a fmt::Write and saves
268
323
// off I/O errors. instead of discarding them
@@ -303,7 +358,7 @@ pub trait Write: crate::ErrorType {
303
358
304
359
/// Blocking seek within streams.
305
360
///
306
- /// Semantics are the same as [`std::io::Seek`], check its documentation for details .
361
+ /// This trait is the `embedded-io` equivalent of [`std::io::Seek`].
307
362
pub trait Seek : crate :: ErrorType {
308
363
/// Seek to an offset, in bytes, in a stream.
309
364
fn seek ( & mut self , pos : crate :: SeekFrom ) -> Result < u64 , Self :: Error > ;
0 commit comments