mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-13 00:40:22 +00:00
93c30a953d
Switch to a procedural implementation of the `query_group!` macro, residing in the `components/salsa_macros` subcrate. Allow the user to override the invoked function via `salsa::invoke(...)` and the name of the generated query type via `salsa::query_type(...)`. In all tests, replace the `salsa::query_group! { ... }` invocations with the new attribute-style `#[salsa::query_group]` macro, and change them to the new naming scheme for query types (`...Query`). Update README, examples, and documentation.
22 lines
556 B
Rust
22 lines
556 B
Rust
pub(crate) trait Counter: salsa::Database {
|
|
fn increment(&self) -> usize;
|
|
}
|
|
|
|
#[salsa::query_group]
|
|
pub(crate) trait Database: Counter {
|
|
fn memoized(&self) -> usize;
|
|
#[salsa::volatile]
|
|
fn volatile(&self) -> usize;
|
|
}
|
|
|
|
/// Because this query is memoized, we only increment the counter
|
|
/// the first time it is invoked.
|
|
fn memoized(db: &impl Database) -> usize {
|
|
db.volatile()
|
|
}
|
|
|
|
/// Because this query is volatile, each time it is invoked,
|
|
/// we will increment the counter.
|
|
fn volatile(db: &impl Database) -> usize {
|
|
db.increment()
|
|
}
|