mirror of
https://github.com/Drop-OSS/drop
synced 2026-08-27 14:23:05 -04:00
implement display trait for archive error and err code
This commit is contained in:
parent
98168ddcf1
commit
fe0b023a2d
1 changed files with 31 additions and 3 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use std::error;
|
||||
use std::fmt;
|
||||
use archive;
|
||||
|
||||
pub type ArchiveResult<T> = Result<T, ArchiveError>;
|
||||
|
|
@ -5,13 +7,39 @@ pub type ArchiveResult<T> = Result<T, ArchiveError>;
|
|||
#[derive(Debug)]
|
||||
pub struct ErrCode(i32);
|
||||
|
||||
impl fmt::Display for ErrCode {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ArchiveError {
|
||||
Consumed,
|
||||
Sys(ErrCode, String),
|
||||
ReadFailure,
|
||||
WriteFailure,
|
||||
HeaderPosition,
|
||||
Sys(ErrCode, String),
|
||||
}
|
||||
|
||||
impl error::Error for ArchiveError {
|
||||
fn description(&self) -> &str {
|
||||
match self {
|
||||
&ArchiveError::Consumed => "Builder already consumed",
|
||||
&ArchiveError::HeaderPosition => "Header position expected to be 0",
|
||||
&ArchiveError::Sys(_, _) => "libarchive system error",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ArchiveError {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&ArchiveError::Consumed => write!(fmt, "Builder already consumed"),
|
||||
&ArchiveError::HeaderPosition => write!(fmt, "Header position expected to be 0"),
|
||||
&ArchiveError::Sys(ref code, ref msg) => {
|
||||
write!(fmt, "{} (libarchive err_code={})", msg, code)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a archive::Handle> for ArchiveError {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue