Use io::Error::downcast in 1.79 (#1754)

* Bump msrv of binstalk-downloader, binstalk and cargo-binstall to 1.79

* Update From<io::Error> for DownloadError

to use io::Error::downcast

* Update From<io::Error> for BinstallError

* fix dmt
This commit is contained in:
Jiahao XU 2024-06-14 18:00:53 +10:00 committed by GitHub
parent dfa230f039
commit 34cca9f415
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 7 additions and 31 deletions

View file

@ -44,20 +44,8 @@ pub enum DownloadError {
impl From<io::Error> for DownloadError {
fn from(err: io::Error) -> Self {
if err.get_ref().is_some() {
let kind = err.kind();
let inner = err
.into_inner()
.expect("err.get_ref() returns Some, so err.into_inner() should also return Some");
inner
.downcast()
.map(|b| *b)
.unwrap_or_else(|err| DownloadError::Io(io::Error::new(kind, err)))
} else {
DownloadError::Io(err)
}
err.downcast::<DownloadError>()
.unwrap_or_else(DownloadError::Io)
}
}