mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-06 04:00:02 +00:00
Manually impl From<io::Error> for BinstallError
so that if the `io::Error` wraps a `BinstallError`, we would just unwrap it and return the inner `BinstallError`. Otherwise, just wrap the `io::Error` in a `BinstallError`. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
1161a60968
commit
aba1ba7b6d
1 changed files with 21 additions and 1 deletions
|
@ -75,7 +75,7 @@ pub enum BinstallError {
|
||||||
/// - Exit: 74
|
/// - Exit: 74
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
#[diagnostic(severity(error), code(binstall::io))]
|
#[diagnostic(severity(error), code(binstall::io))]
|
||||||
Io(#[from] std::io::Error),
|
Io(std::io::Error),
|
||||||
|
|
||||||
/// An error interacting with the crates.io API.
|
/// An error interacting with the crates.io API.
|
||||||
///
|
///
|
||||||
|
@ -231,3 +231,23 @@ impl Termination for BinstallError {
|
||||||
code
|
code
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<std::io::Error> for BinstallError {
|
||||||
|
fn from(err: std::io::Error) -> Self {
|
||||||
|
let is_inner_binstall_err = err
|
||||||
|
.get_ref()
|
||||||
|
.map(|e| e.is::<BinstallError>())
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
if is_inner_binstall_err {
|
||||||
|
let inner = err
|
||||||
|
.into_inner()
|
||||||
|
.expect("err.get_ref() returns Some, so err.into_inner() should als return Some");
|
||||||
|
*inner
|
||||||
|
.downcast()
|
||||||
|
.expect("The inner err is tested to be BinstallError")
|
||||||
|
} else {
|
||||||
|
BinstallError::Io(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue