tokio_tar/
error.rs

1use std::borrow::Cow;
2use std::error;
3use std::fmt;
4use std::io;
5
6/// Error that occurred while reading or writing tar file.
7///
8/// The source may be an IO error from the operating system or a custom error with additional
9/// context.
10#[derive(Debug)]
11pub struct TarError {
12    desc: Cow<'static, str>,
13    io: io::Error,
14}
15
16impl TarError {
17    pub(crate) fn new(desc: impl Into<Cow<'static, str>>, err: io::Error) -> TarError {
18        TarError {
19            desc: desc.into(),
20            io: err,
21        }
22    }
23}
24
25impl error::Error for TarError {
26    fn description(&self) -> &str {
27        &self.desc
28    }
29
30    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
31        Some(&self.io)
32    }
33}
34
35impl fmt::Display for TarError {
36    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
37        self.desc.fmt(f)
38    }
39}
40
41impl From<TarError> for io::Error {
42    fn from(t: TarError) -> io::Error {
43        io::Error::new(t.io.kind(), t)
44    }
45}