clamav_stream/
error.rs

1use std::{error::Error as StdError, io, str::Utf8Error};
2
3/// The error type returned by [`ScannedStream`](crate::ScannedStream).
4#[derive(Debug, thiserror::Error)]
5pub enum Error {
6    /// Equivalent to the [`std::io::Error`](std::io::Error).
7    #[error("io error: {0}")]
8    Io(io::Error),
9
10    /// Equivalent to the [`std::str::Utf8Error`](std::str::Utf8Error).
11    #[error("utf8 error: {0}")]
12    Utf8(Utf8Error),
13
14    /// An error returned while consuming the inner stream.
15    #[error("stream error: {0}")]
16    Stream(Box<dyn StdError + Send + Sync>),
17
18    /// Infected stream error with message from the clamav.
19    #[error("{0}")]
20    Scan(String),
21}
22
23impl From<io::Error> for Error {
24    fn from(error: io::Error) -> Self {
25        Self::Io(error)
26    }
27}
28
29impl From<Utf8Error> for Error {
30    fn from(error: Utf8Error) -> Self {
31        Self::Utf8(error)
32    }
33}
34
35impl PartialEq for Error {
36    fn eq(&self, other: &Self) -> bool {
37        format!("{self}").as_str() == format!("{other}").as_str()
38    }
39}