mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 13:08:42 +00:00
Refactor From<io::Error> for BinstallError
Avoid one `expect`. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
c5a2a89361
commit
2f38925ee4
1 changed files with 7 additions and 8 deletions
|
@ -234,18 +234,17 @@ impl Termination for BinstallError {
|
||||||
|
|
||||||
impl From<std::io::Error> for BinstallError {
|
impl From<std::io::Error> for BinstallError {
|
||||||
fn from(err: std::io::Error) -> Self {
|
fn from(err: std::io::Error) -> Self {
|
||||||
let is_inner_binstall_err = err
|
if err.get_ref().is_some() {
|
||||||
.get_ref()
|
let kind = err.kind();
|
||||||
.map(|e| e.is::<BinstallError>())
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
if is_inner_binstall_err {
|
|
||||||
let inner = err
|
let inner = err
|
||||||
.into_inner()
|
.into_inner()
|
||||||
.expect("err.get_ref() returns Some, so err.into_inner() should als return Some");
|
.expect("err.get_ref() returns Some, so err.into_inner() should also return Some");
|
||||||
*inner
|
|
||||||
|
inner
|
||||||
.downcast()
|
.downcast()
|
||||||
.expect("The inner err is tested to be BinstallError")
|
.map(|b| *b)
|
||||||
|
.unwrap_or_else(|err| BinstallError::Io(std::io::Error::new(kind, err)))
|
||||||
} else {
|
} else {
|
||||||
BinstallError::Io(err)
|
BinstallError::Io(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue