aphrodite/
errors.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//! Stuff related to errors.

/// An error used by aphrodite
pub struct Error<'a> {
    message: &'a str,
    code: i16
}

impl<'a> Error<'a> {
    /// Creates a new error.
    pub fn new(message: &'a str, code: i16) -> Self {
        Error { message, code }
    }
}

impl core::fmt::Debug for Error<'_> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        f.write_str(core::str::from_utf8(&crate::i16_as_u8_slice(self.code)).unwrap())?;
        f.write_str(": ")?;
        f.write_str(self.message)
    }
}

impl core::fmt::Display for Error<'_> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        f.write_str(core::str::from_utf8(&crate::i16_as_u8_slice(self.code)).unwrap())?;
        f.write_str(": ")?;
        f.write_str(self.message)
    }
}

impl core::error::Error for Error<'_> {}