file_type/
error.rs

1use alloc::string::{String, ToString};
2
3/// File type result type
4pub type Result<T, E = Error> = core::result::Result<T, E>;
5
6/// Errors that can occur when determining the file type
7#[derive(Clone, Debug, Eq, PartialEq)]
8pub struct Error {
9    message: String,
10}
11
12impl Error {
13    pub(crate) fn new<S: AsRef<str>>(message: S) -> Error {
14        Error {
15            message: message.as_ref().to_string(),
16        }
17    }
18}
19
20#[cfg(feature = "std")]
21impl std::error::Error for Error {}
22
23impl core::fmt::Display for Error {
24    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
25        write!(f, "{}", self.message)
26    }
27}
28
29#[cfg(test)]
30mod tests {
31    use super::*;
32
33    #[test]
34    fn test_error() {
35        let error = Error::new("test");
36        assert_eq!(error.to_string(), "test");
37    }
38}