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 {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
let is_inner_binstall_err = err
|
||||
.get_ref()
|
||||
.map(|e| e.is::<BinstallError>())
|
||||
.unwrap_or_default();
|
||||
if err.get_ref().is_some() {
|
||||
let kind = err.kind();
|
||||
|
||||
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
|
||||
.expect("err.get_ref() returns Some, so err.into_inner() should also return Some");
|
||||
|
||||
inner
|
||||
.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 {
|
||||
BinstallError::Io(err)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue