find_simdoc/
errors.rs

1//! Error definitions.
2use std::error::Error;
3use std::{fmt, result};
4
5/// A specialized Result type for this library.
6pub type Result<T, E = FindSimdocError> = result::Result<T, E>;
7
8/// Errors in this library.
9#[derive(Debug)]
10pub enum FindSimdocError {
11    /// Contains [`InputError`].
12    Input(InputError),
13}
14
15impl fmt::Display for FindSimdocError {
16    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
17        match self {
18            Self::Input(e) => e.fmt(f),
19        }
20    }
21}
22
23impl Error for FindSimdocError {}
24
25impl FindSimdocError {
26    pub(crate) const fn input(msg: &'static str) -> Self {
27        Self::Input(InputError { msg })
28    }
29}
30
31/// Error used when the input argument is invalid.
32#[derive(Debug)]
33pub struct InputError {
34    msg: &'static str,
35}
36
37impl fmt::Display for InputError {
38    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
39        write!(f, "InputError: {}", self.msg)
40    }
41}