Skip to content

Commit 01a164c

Browse files
Ecazares15ShadowCurse
authored andcommitted
Implement std::error::Error for Error Types
Updated Error<E> in serial.rs to implement std::error::Error. Signed-off-by: Eddie Cazares <[email protected]>
1 parent cb7c365 commit 01a164c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

vm-superio/src/serial.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
//! This is done by emulating an UART serial port.
1212
1313
use std::collections::VecDeque;
14+
use std::error::Error as StdError;
15+
use std::fmt;
1416
use std::io::{self, Write};
1517
use std::result::Result;
1618
use std::sync::Arc;
@@ -289,6 +291,18 @@ pub enum Error<E> {
289291
FullFifo,
290292
}
291293

294+
impl<E: fmt::Display> fmt::Display for Error<E> {
295+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
296+
match self {
297+
Error::Trigger(e) => write!(f, "Failed to trigger interrupt: {}", e),
298+
Error::IOError(e) => write!(f, "Couldn't write/flush to the given destination: {}", e),
299+
Error::FullFifo => write!(f, "No space left in FIFO"),
300+
}
301+
}
302+
}
303+
304+
impl<E: StdError> StdError for Error<E> {}
305+
292306
impl<T: Trigger, W: Write> Serial<T, NoEvents, W> {
293307
/// Creates a new `Serial` instance which writes the guest's output to
294308
/// `out` and uses `trigger` object to notify the driver about new

0 commit comments

Comments
 (0)