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