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
pub mod parse {
    use bstr::BString;

    /// The error returned when creating `Integer` from byte string.
    #[derive(Debug, thiserror::Error, Eq, PartialEq)]
    #[allow(missing_docs)]
    #[error("Could not decode '{}': {}", .input, .message)]
    pub struct Error {
        pub message: &'static str,
        pub input: BString,
        #[source]
        pub utf8_err: Option<std::str::Utf8Error>,
    }

    impl Error {
        pub(crate) fn new(message: &'static str, input: impl Into<BString>) -> Self {
            Error {
                message,
                input: input.into(),
                utf8_err: None,
            }
        }

        pub(crate) fn with_err(mut self, err: std::str::Utf8Error) -> Self {
            self.utf8_err = Some(err);
            self
        }
    }
}