pub trait Track: Trackable {
// Required method
fn valid(&self, constraint: &Constraint<Self>) -> bool;
// Provided methods
fn track(&self) -> Tracked<'_, Self> { ... }
fn track_mut(&mut self) -> TrackedMut<'_, Self> { ... }
fn track_with<'a>(
&'a self,
constraint: &'a Constraint<Self>
) -> Tracked<'a, Self> { ... }
fn track_mut_with<'a>(
&'a mut self,
constraint: &'a Constraint<Self>
) -> TrackedMut<'a, Self> { ... }
}Expand description
A trackable type.
This is implemented by types that have an implementation block annotated
with #[track] and for trait objects whose traits are annotated with
#[track]. For more details, see its documentation.
Required Methods§
sourcefn valid(&self, constraint: &Constraint<Self>) -> bool
fn valid(&self, constraint: &Constraint<Self>) -> bool
Whether this value fulfills the given constraints.
Such constraints can be generated with track_with or track_mut_with.
Provided Methods§
sourcefn track(&self) -> Tracked<'_, Self>
fn track(&self) -> Tracked<'_, Self>
Start tracking all accesses to a value.
Examples found in repository?
examples/calc.rs (line 19)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
fn main() {
// Create some scripts in the calc language. This language supports addition
// and `eval` statements referring to other files.
let mut files = Files(HashMap::new());
files.write("alpha.calc", "2 + eval beta.calc");
files.write("beta.calc", "2 + 3");
files.write("gamma.calc", "8 + 3");
// [Miss] The cache is empty.
assert_eq!(evaluate("eval alpha.calc", files.track()), 7);
// [Miss] This is not a top-level hit because this exact string was never
// passed to `evaluate`, but this does not compute "2 + 3" again.
assert_eq!(evaluate("eval beta.calc", files.track()), 5);
// Modify the gamma file.
files.write("gamma.calc", "42");
// [Hit] This is a hit because `gamma.calc` isn't referenced by `alpha.calc`.
assert_eq!(evaluate("eval alpha.calc", files.track()), 7);
// Modify the beta file.
files.write("beta.calc", "4 + eval gamma.calc");
// [Miss] This is a miss because `beta.calc` changed.
assert_eq!(evaluate("eval alpha.calc", files.track()), 48);
}sourcefn track_mut(&mut self) -> TrackedMut<'_, Self>
fn track_mut(&mut self) -> TrackedMut<'_, Self>
Start tracking all accesses and mutations to a value.
sourcefn track_with<'a>(
&'a self,
constraint: &'a Constraint<Self>
) -> Tracked<'a, Self>
fn track_with<'a>( &'a self, constraint: &'a Constraint<Self> ) -> Tracked<'a, Self>
Start tracking all accesses into a constraint.
sourcefn track_mut_with<'a>(
&'a mut self,
constraint: &'a Constraint<Self>
) -> TrackedMut<'a, Self>
fn track_mut_with<'a>( &'a mut self, constraint: &'a Constraint<Self> ) -> TrackedMut<'a, Self>
Start tracking all accesses and mutations into a constraint.