attribute_search_engine/
error.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
33
use std::{fmt, result};

/// Common Result type for the attribute search engine.
pub type Result<T> = result::Result<T, SearchEngineError>;

/// Enum of all possible error types that the attribute search engine
/// can throw by itself.
#[derive(Debug, PartialEq)]
pub enum SearchEngineError {
    /// Will be thrown if an unknown attribute is requested,
    /// for example when inserting or by a [Query](crate::query::Query).
    UnknownAttribute,

    /// A [Query](crate::query::Query) value cannot be processed by a
    /// specific search index because the string can't be converted to the expected type.
    MismatchedQueryType,

    /// A [Query](crate::query::Query) cannot be processed because it is
    /// not supported.
    UnsupportedQuery,
}

impl std::error::Error for SearchEngineError {}

impl fmt::Display for SearchEngineError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            SearchEngineError::UnknownAttribute => write!(f, "Unknown attribute error"),
            SearchEngineError::MismatchedQueryType => write!(f, "Mismatched query type"),
            SearchEngineError::UnsupportedQuery => write!(f, "Unsupported query"),
        }
    }
}