attribute_search_engine/
error.rs

1use std::{fmt, result};
2
3/// Common Result type for the attribute search engine.
4pub type Result<T> = result::Result<T, SearchEngineError>;
5
6/// Enum of all possible error types that the attribute search engine
7/// can throw by itself.
8#[derive(Debug, PartialEq)]
9pub enum SearchEngineError {
10    /// Will be thrown if an unknown attribute is requested,
11    /// for example when inserting or by a [Query](crate::query::Query).
12    UnknownAttribute,
13
14    /// A [Query](crate::query::Query) value cannot be processed by a
15    /// specific search index because the string can't be converted to the expected type.
16    MismatchedQueryType,
17
18    /// A [Query](crate::query::Query) cannot be processed because it is
19    /// not supported.
20    UnsupportedQuery,
21}
22
23impl std::error::Error for SearchEngineError {}
24
25impl fmt::Display for SearchEngineError {
26    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27        match self {
28            SearchEngineError::UnknownAttribute => write!(f, "Unknown attribute error"),
29            SearchEngineError::MismatchedQueryType => write!(f, "Mismatched query type"),
30            SearchEngineError::UnsupportedQuery => write!(f, "Unsupported query"),
31        }
32    }
33}