rdif_base/io.rs
1use core::fmt::Display;
2
3pub type Result<T = ()> = core::result::Result<T, Error>;
4
5pub trait Read {
6 /// Read data from the device. Returns the number of bytes read.
7 fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
8 /// Returns true if the device is ready to read.
9 fn can_read(&self) -> bool;
10}
11
12pub trait Write {
13 /// Write data to the device. Returns the number of bytes written.
14 fn write(&mut self, buf: &[u8]) -> Result<usize>;
15 /// Returns true if the device is ready to accept data.
16 fn can_write(&self) -> bool;
17}
18
19impl core::error::Error for Error {}
20
21impl Display for Error {
22 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
23 write!(f, "{:?}", self)
24 }
25}
26
27#[derive(Debug, Clone)]
28pub enum Error {
29 /// Unspecified error kind.
30 Other(&'static str),
31 /// The operation lacked the necessary privileges to complete.
32 PermissionDenied,
33 /// Hardware not available.
34 NotAvailable,
35 /// The operation failed because a pipe was closed.
36 BrokenPipe,
37 /// parameter was incorrect.
38 InvalidParameter { name: &'static str },
39 /// Data not valid for the operation were encountered.
40 InvalidData,
41 /// The I/O operation's timeout expired, causing it to be canceled.
42 TimedOut,
43 /// This operation was interrupted.
44 ///
45 /// Interrupted operations can typically be retried.
46 Interrupted,
47 /// This operation is unsupported on this platform.
48 ///
49 /// This means that the operation can never succeed.
50 Unsupported,
51 /// An operation could not be completed, because it failed
52 /// to allocate enough memory.
53 OutOfMemory,
54 /// An attempted write could not write any data.
55 WriteZero,
56}