pub struct Revision(/* private fields */);Expand description
A monotonic version stamp for the database.
Every time an input changes, the Database advances its
revision by one. The engine never compares values to decide whether a cached
query is still good — it compares revisions, which is a single integer compare
regardless of how large the cached value is. Two stamps live on every memoized
query: the revision it was last verified at, and the revision its value last
changed at. A query is still valid when none of its dependencies changed
after it was last verified, and that whole judgement reduces to > on
Revision.
Revisions are opaque and ordered: newer revisions compare greater than older
ones. The concrete number is exposed through as_u64 for
logging and tests, but carries no meaning beyond its order.
§Examples
The revision advances only when an input actually changes value:
use query_lang::{Database, System, QueryError};
struct S;
impl System for S {
type Key = u32;
type Value = u32;
fn compute(&self, _db: &Database<Self>, key: &u32) -> Result<u32, QueryError> {
Ok(*key)
}
}
let mut db = Database::new(S);
let start = db.revision();
db.set(1, 10);
assert!(db.revision() > start); // a new input advanced the clock
let after_first = db.revision();
db.set(1, 10); // same value — no real change
assert_eq!(db.revision(), after_first); // the clock did not moveImplementations§
Source§impl Revision
impl Revision
Sourcepub const fn as_u64(self) -> u64
pub const fn as_u64(self) -> u64
The underlying counter value.
Useful for logging and assertions. The number has no meaning on its own; only the order between two revisions is significant.
§Examples
use query_lang::{Database, System, QueryError};
struct S;
impl System for S {
type Key = u32;
type Value = u32;
fn compute(&self, _db: &Database<Self>, k: &u32) -> Result<u32, QueryError> { Ok(*k) }
}
let mut db = Database::new(S);
assert_eq!(db.revision().as_u64(), 0);
db.set(1, 1);
assert_eq!(db.revision().as_u64(), 1);