channels_io/error.rs
1//! Error traits that describe IO errors.
2
3/// Common functionality for [`ReadError`] and [`WriteError`].
4///
5/// [`ReadError`]: trait@ReadError
6/// [`WriteError`]: trait@WriteError
7pub trait IoError {
8 /// Checks whether the given error indicates that the operation should be retried.
9 fn should_retry(&self) -> bool;
10}
11
12/// A trait that describes an error returned by [`Read`] and [`AsyncRead`].
13///
14/// [`Read`]: trait@crate::Read
15/// [`AsyncRead`]: trait@crate::AsyncRead
16pub trait ReadError: IoError {
17 /// Create a new End-Of-File error.
18 fn eof() -> Self;
19}
20
21/// A trait that describes an error returned by [`Write`] and [`AsyncWrite`].
22///
23/// [`Write`]: trait@crate::Write
24/// [`AsyncWrite`]: trait@crate::AsyncWrite
25pub trait WriteError: IoError {
26 /// Create a new error that indicates zero written bytes when writing.
27 fn write_zero() -> Self;
28}