Skip to content

Commit 7aaa585

Browse files
committed
Rename trait Io to ErrorType.
1 parent e363868 commit 7aaa585

File tree

8 files changed

+24
-23
lines changed

8 files changed

+24
-23
lines changed

embedded-io-async/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ extern crate alloc;
1010
mod impls;
1111

1212
pub use embedded_io::{
13-
Error, ErrorKind, Io, ReadExactError, ReadReady, SeekFrom, WriteAllError, WriteReady,
13+
Error, ErrorKind, ErrorType, ReadExactError, ReadReady, SeekFrom, WriteAllError, WriteReady,
1414
};
1515

1616
/// Async reader.
1717
///
1818
/// Semantics are the same as [`std::io::Read`], check its documentation for details.
19-
pub trait Read: Io {
19+
pub trait Read: ErrorType {
2020
/// Pull some bytes from this source into the specified buffer, returning how many bytes were read.
2121
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>;
2222

@@ -40,7 +40,7 @@ pub trait Read: Io {
4040
/// Async buffered reader.
4141
///
4242
/// Semantics are the same as [`std::io::BufRead`], check its documentation for details.
43-
pub trait BufRead: Io {
43+
pub trait BufRead: ErrorType {
4444
/// Return the contents of the internal buffer, filling it with more data from the inner reader if it is empty.
4545
async fn fill_buf(&mut self) -> Result<&[u8], Self::Error>;
4646

@@ -51,7 +51,7 @@ pub trait BufRead: Io {
5151
/// Async writer.
5252
///
5353
/// Semantics are the same as [`std::io::Write`], check its documentation for details.
54-
pub trait Write: Io {
54+
pub trait Write: ErrorType {
5555
/// Write a buffer into this writer, returning how many bytes were written.
5656
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>;
5757

@@ -77,7 +77,7 @@ pub trait Write: Io {
7777
/// Async seek within streams.
7878
///
7979
/// Semantics are the same as [`std::io::Seek`], check its documentation for details.
80-
pub trait Seek: Io {
80+
pub trait Seek: ErrorType {
8181
/// Seek to an offset, in bytes, in a stream.
8282
async fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error>;
8383

embedded-io/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Moved `embedded_io::blocking` to the crate root.
1212
- Split async traits to the `embedded-io-async` crate.
1313
- Split async trait adapters to separate crates.
14+
- Rename trait `Io` to `ErrorKind`, for consistency with `embedded-hal`.
1415

1516
## 0.4.0 - 2022-11-25
1617

embedded-io/src/adapters.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<T: ?Sized> FromStd<T> {
4040
}
4141
}
4242

43-
impl<T: ?Sized> crate::Io for FromStd<T> {
43+
impl<T: ?Sized> crate::ErrorType for FromStd<T> {
4444
type Error = std::io::Error;
4545
}
4646

embedded-io/src/impls/boxx.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use crate::{BufRead, Io, Read, ReadReady, Seek, Write, WriteReady};
1+
use crate::{BufRead, ErrorType, Read, ReadReady, Seek, Write, WriteReady};
22
use alloc::boxed::Box;
33

44
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
5-
impl<T: ?Sized + Io> Io for Box<T> {
5+
impl<T: ?Sized + ErrorType> ErrorType for Box<T> {
66
type Error = T::Error;
77
}
88

embedded-io/src/impls/slice_mut.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use crate::{Io, Write};
1+
use crate::{ErrorType, Write};
22
use core::mem;
33

4-
impl Io for &mut [u8] {
4+
impl ErrorType for &mut [u8] {
55
type Error = core::convert::Infallible;
66
}
77

embedded-io/src/impls/slice_ref.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::{BufRead, Io, Read};
1+
use crate::{BufRead, ErrorType, Read};
22

3-
impl Io for &[u8] {
3+
impl ErrorType for &[u8] {
44
type Error = core::convert::Infallible;
55
}
66

embedded-io/src/impls/vec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use crate::{Io, Write};
1+
use crate::{ErrorType, Write};
22
use alloc::vec::Vec;
33

44
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
5-
impl Io for Vec<u8> {
5+
impl ErrorType for Vec<u8> {
66
type Error = core::convert::Infallible;
77
}
88

embedded-io/src/lib.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Error for ErrorKind {
5555
}
5656
}
5757

58-
/// Base trait for all IO traits.
58+
/// Base trait for all IO traits, defining the error type.
5959
///
6060
/// All IO operations of all traits return the error defined in this trait.
6161
///
@@ -64,12 +64,12 @@ impl Error for ErrorKind {
6464
/// This is very convenient when writing generic code, it means you have to
6565
/// handle a single error type `T::Error`, instead of `<T as Read>::Error` and `<T as Write>::Error`
6666
/// which might be different types.
67-
pub trait Io {
67+
pub trait ErrorType {
6868
/// Error type of all the IO operations on this type.
6969
type Error: Error;
7070
}
7171

72-
impl<T: ?Sized + crate::Io> crate::Io for &mut T {
72+
impl<T: ?Sized + crate::ErrorType> crate::ErrorType for &mut T {
7373
type Error = T::Error;
7474
}
7575

@@ -150,7 +150,7 @@ impl<E: fmt::Debug> std::error::Error for WriteAllError<E> {}
150150
/// Blocking reader.
151151
///
152152
/// Semantics are the same as [`std::io::Read`], check its documentation for details.
153-
pub trait Read: crate::Io {
153+
pub trait Read: crate::ErrorType {
154154
/// Pull some bytes from this source into the specified buffer, returning how many bytes were read.
155155
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>;
156156

@@ -174,7 +174,7 @@ pub trait Read: crate::Io {
174174
/// Blocking buffered reader.
175175
///
176176
/// Semantics are the same as [`std::io::BufRead`], check its documentation for details.
177-
pub trait BufRead: crate::Io {
177+
pub trait BufRead: crate::ErrorType {
178178
/// Return the contents of the internal buffer, filling it with more data from the inner reader if it is empty.
179179
fn fill_buf(&mut self) -> Result<&[u8], Self::Error>;
180180

@@ -185,7 +185,7 @@ pub trait BufRead: crate::Io {
185185
/// Blocking writer.
186186
///
187187
/// Semantics are the same as [`std::io::Write`], check its documentation for details.
188-
pub trait Write: crate::Io {
188+
pub trait Write: crate::ErrorType {
189189
/// Write a buffer into this writer, returning how many bytes were written.
190190
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>;
191191

@@ -246,7 +246,7 @@ pub trait Write: crate::Io {
246246
/// Blocking seek within streams.
247247
///
248248
/// Semantics are the same as [`std::io::Seek`], check its documentation for details.
249-
pub trait Seek: crate::Io {
249+
pub trait Seek: crate::ErrorType {
250250
/// Seek to an offset, in bytes, in a stream.
251251
fn seek(&mut self, pos: crate::SeekFrom) -> Result<u64, Self::Error>;
252252

@@ -266,7 +266,7 @@ pub trait Seek: crate::Io {
266266
///
267267
/// This allows using a [`Read`] or [`BufRead`] in a nonblocking fashion, i.e. trying to read
268268
/// only when it is ready.
269-
pub trait ReadReady: crate::Io {
269+
pub trait ReadReady: crate::ErrorType {
270270
/// Get whether the reader is ready for immediately reading.
271271
///
272272
/// This usually means that there is either some bytes have been received and are buffered and ready to be read,
@@ -280,7 +280,7 @@ pub trait ReadReady: crate::Io {
280280
///
281281
/// This allows using a [`Write`] in a nonblocking fashion, i.e. trying to write
282282
/// only when it is ready.
283-
pub trait WriteReady: crate::Io {
283+
pub trait WriteReady: crate::ErrorType {
284284
/// Get whether the writer is ready for immediately writing.
285285
///
286286
/// This usually means that there is free space in the internal transmit buffer.

0 commit comments

Comments
 (0)