mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: Add BlockResult, From<io::Error>
Add the public BlockResult type alias and a From<io::Error> impl so that bare I/O errors automatically convert into BlockError with BlockErrorKind::Io via the ? operator. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
4c29548736
commit
9be154b03c
@@ -18,6 +18,7 @@
|
||||
|
||||
use std::error::Error as StdError;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Small, stable classification of block errors.
|
||||
@@ -219,3 +220,12 @@ impl StdError for BlockError {
|
||||
.map(|e| e.as_ref() as &(dyn StdError + 'static))
|
||||
}
|
||||
}
|
||||
|
||||
/// Convenience: wrap an `io::Error` as `BlockErrorKind::Io`.
|
||||
impl From<io::Error> for BlockError {
|
||||
fn from(e: io::Error) -> Self {
|
||||
Self::new(BlockErrorKind::Io, e)
|
||||
}
|
||||
}
|
||||
|
||||
pub type BlockResult<T> = Result<T, BlockError>;
|
||||
|
||||
Reference in New Issue
Block a user