| 1 | use std::{ |
| 2 | borrow::Cow, |
| 3 | fmt::{Display, Formatter}, |
| 4 | }; |
| 5 | |
| 6 | #[derive(Debug)] |
| 7 | pub(crate) struct QueryError { |
| 8 | reason: Cow<'static, str>, |
| 9 | } |
| 10 | |
| 11 | impl QueryError { |
| 12 | #[inline] |
| 13 | pub(crate) fn new<I: Into<Cow<'static, str>>>(reason: I) -> Self { |
| 14 | Self { |
| 15 | reason: reason.into(), |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | #[inline] |
| 20 | pub(super) fn missing_value() -> Self { |
| 21 | Self { |
| 22 | reason: "Missing value".into(), |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | impl Display for QueryError { |
| 28 | fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
| 29 | write!(f, "{}", self.reason) |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | impl From<regex::Error> for QueryError { |
| 34 | fn from(err: regex::Error) -> Self { |
| 35 | Self::new(err.to_string()) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | pub(super) type QueryResult<T> = Result<T, QueryError>; |