driver_interface/io/mod.rs
1pub type Result<T = ()> = core::result::Result<T, Error>;
2
3pub trait Read {
4 fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
5 fn can_read(&self) -> bool;
6}
7
8pub trait Write {
9 fn write(&mut self, buf: &[u8]) -> Result<usize>;
10 fn can_write(&self) -> bool;
11}
12
13#[derive(Debug, Copy, Clone)]
14pub struct Error {
15 pub kind: ErrorKind,
16 pub message: &'static str,
17}
18
19#[derive(Debug, Copy, Clone, Eq, PartialEq)]
20pub enum ErrorKind {
21 /// Unspecified error kind.
22 Other,
23
24 /// An entity was not found, often a file.
25 NotFound,
26 /// The operation lacked the necessary privileges to complete.
27 PermissionDenied,
28 /// The connection was refused by the remote server.
29 ConnectionRefused,
30 /// The connection was reset by the remote server.
31 ConnectionReset,
32 /// The connection was aborted (terminated) by the remote server.
33 ConnectionAborted,
34 /// The network operation failed because it was not connected yet.
35 NotConnected,
36 /// A socket address could not be bound because the address is already in
37 /// use elsewhere.
38 AddrInUse,
39 /// A nonexistent interface was requested or the requested address was not
40 /// local.
41 AddrNotAvailable,
42 /// The operation failed because a pipe was closed.
43 BrokenPipe,
44 /// An entity already exists, often a file.
45 AlreadyExists,
46 /// A parameter was incorrect.
47 InvalidInput,
48 /// Data not valid for the operation were encountered.
49 ///
50 /// Unlike [`InvalidInput`], this typically means that the operation
51 /// parameters were valid, however the error was caused by malformed
52 /// input data.
53 ///
54 /// For example, a function that reads a file into a string will error with
55 /// `InvalidData` if the file's contents are not valid UTF-8.
56 ///
57 /// [`InvalidInput`]: ErrorKind::InvalidInput
58 InvalidData,
59 /// The I/O operation's timeout expired, causing it to be canceled.
60 TimedOut,
61 /// This operation was interrupted.
62 ///
63 /// Interrupted operations can typically be retried.
64 Interrupted,
65 /// This operation is unsupported on this platform.
66 ///
67 /// This means that the operation can never succeed.
68 Unsupported,
69 /// An operation could not be completed, because it failed
70 /// to allocate enough memory.
71 OutOfMemory,
72 /// An attempted write could not write any data.
73 WriteZero,
74}