1use std::{error, fmt};
2
3use tokio::io::{self, Error};
4
5#[derive(Debug)]
6pub struct TarError {
7 desc: String,
8 io: io::Error,
9}
10
11impl TarError {
12 pub fn new(desc: &str, err: Error) -> TarError {
13 TarError {
14 desc: desc.to_string(),
15 io: err,
16 }
17 }
18}
19
20impl error::Error for TarError {
21 fn description(&self) -> &str {
22 &self.desc
23 }
24
25 fn source(&self) -> Option<&(dyn error::Error + 'static)> {
26 Some(&self.io)
27 }
28}
29
30impl fmt::Display for TarError {
31 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
32 self.desc.fmt(f)
33 }
34}
35
36impl From<TarError> for Error {
37 fn from(t: TarError) -> Error {
38 Error::new(t.io.kind(), t)
39 }
40}