sim: simflash: Convert to thiserror
The thiserror crate seems to be getting more momentum in the community
than failure. Switch to this for deriving our own error type.
Signed-off-by: David Brown <david.brown@linaro.org>
diff --git a/sim/simflash/Cargo.toml b/sim/simflash/Cargo.toml
index 1622255..e585d16 100644
--- a/sim/simflash/Cargo.toml
+++ b/sim/simflash/Cargo.toml
@@ -5,7 +5,6 @@
edition = "2018"
[dependencies]
-failure = "0.1.6"
-failure_derive = "0.1.6"
rand = "0.7"
log = "0.4"
+thiserror = "1.0"
diff --git a/sim/simflash/src/lib.rs b/sim/simflash/src/lib.rs
index 734b3c1..fa83c3e 100644
--- a/sim/simflash/src/lib.rs
+++ b/sim/simflash/src/lib.rs
@@ -11,7 +11,6 @@
mod pdump;
use crate::pdump::HexDump;
-use failure::Fail;
use log::info;
use rand::{
self,
@@ -26,25 +25,20 @@
path::Path,
slice,
};
+use thiserror::Error;
pub type Result<T> = std::result::Result<T, FlashError>;
-#[derive(Fail, Debug)]
+#[derive(Error, Debug)]
pub enum FlashError {
- #[fail(display = "Offset out of bounds: {}", _0)]
+ #[error("Offset out of bounds: {0}")]
OutOfBounds(String),
- #[fail(display = "Invalid write: {}", _0)]
+ #[error("Invalid write: {0}")]
Write(String),
- #[fail(display = "Write failed by chance: {}", _0)]
+ #[error("Write failed by chance: {0}")]
SimulatedFail(String),
- #[fail(display = "{}", _0)]
- Io(#[cause] io::Error),
-}
-
-impl From<io::Error> for FlashError {
- fn from(error: io::Error) -> Self {
- FlashError::Io(error)
- }
+ #[error("{0}")]
+ Io(#[from] io::Error),
}
// Transition from error-chain.