#[non_exhaustive]pub enum QueryError {
Cycle,
}Expand description
The error returned from Database::get and
System::compute when a query cannot be resolved.
The engine resolves a derived query by running its
compute, which in turn reads other queries. That
recursion terminates only when the dependency graph is acyclic. If a query
asks — directly or through a chain of other queries — for a result that is
itself still being computed, there is no value to return and no way to make
progress: the queries form a cycle. Rather than recurse without bound or
panic, the engine unwinds the whole chain with QueryError::Cycle.
The type is non_exhaustive:
resolution has exactly one failure mode today, and new engine-level failure
modes can be added later without breaking a match that already handles
Cycle.
§Examples
A query that reads itself cannot resolve:
use query_lang::{Database, System, QueryError};
struct SelfReferential;
impl System for SelfReferential {
type Key = u32;
type Value = u32;
fn compute(&self, db: &Database<Self>, key: &u32) -> Result<u32, QueryError> {
// Asking for the very key being computed closes a cycle.
db.get(key)
}
}
let db = Database::new(SelfReferential);
assert_eq!(db.get(&1), Err(QueryError::Cycle));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Cycle
A query depended on itself, directly or through a chain of other queries.
The dependency graph must be acyclic. When it is not, the query that closed the cycle — and every query waiting on it — resolves to this error. The fix is in the query definitions: break the cyclic dependency, usually by splitting the offending query so the two halves no longer wait on each other.
Trait Implementations§
Source§impl Clone for QueryError
impl Clone for QueryError
Source§fn clone(&self) -> QueryError
fn clone(&self) -> QueryError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for QueryError
Source§impl Debug for QueryError
impl Debug for QueryError
Source§impl Display for QueryError
impl Display for QueryError
impl Eq for QueryError
Source§impl Error for QueryError
impl Error for QueryError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()