A simplistic query system, allowing for on-demand, memoized computation.
architect is a way of defining queries. A query is some function which takes a set of arguments and computes some result. By default, results from queries are memoized to prevent recomputation. This does assume that the result of the query is idempotent, given the input arguments.
To make a function into a query, add the crate:
cargo add lume_architect --features deriveOn the type which the query operates on, implement the DatabaseContext trait:
use lume_architect::{Database, DatabaseContext};
struct Provider {
// ... other fields
db: Database,
}
impl DatabaseContext for Provider {
fn db(&self) -> &Database {
&self.db
}
}To declare a method as a query, add the cached_query attribute:
impl Provider {
/// Computes some result, which takes a reeeeally long time.
#[cached_query]
pub fn compute(&self) -> f32 {
// ...
}
}This implementation is heavily based on Rust's query system, based on salsa. Massive credit to the countless of amazing developers who helped create them.