use core::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum QueryError {
Cycle,
TooDeep,
}
impl fmt::Display for QueryError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
QueryError::Cycle => f.write_str("query cycle detected: a query depends on itself"),
QueryError::TooDeep => f.write_str("query resolution exceeded the depth limit"),
}
}
}
impl core::error::Error for QueryError {}
#[cfg(test)]
mod tests {
use super::*;
use alloc::string::ToString;
#[test]
fn test_cycle_display_is_descriptive() {
assert_eq!(
QueryError::Cycle.to_string(),
"query cycle detected: a query depends on itself"
);
}
#[test]
fn test_error_trait_is_implemented() {
fn assert_error<E: core::error::Error>(_: &E) {}
assert_error(&QueryError::Cycle);
}
#[test]
fn test_too_deep_display_is_descriptive() {
assert_eq!(
QueryError::TooDeep.to_string(),
"query resolution exceeded the depth limit"
);
}
#[test]
fn test_equality() {
assert_eq!(QueryError::Cycle, QueryError::Cycle);
}
}