@@ -21,6 +21,32 @@ pub trait Track: Trackable {
2121 fn track_mut ( & mut self ) -> TrackedMut < Self > {
2222 TrackedMut { value : self , constraint : None }
2323 }
24+
25+ /// Start tracking all accesses into a constraint.
26+ #[ inline]
27+ fn track_with < ' a > ( & ' a self , constraint : & ' a Constraint < Self > ) -> Tracked < ' a , Self > {
28+ Tracked {
29+ value : self ,
30+ constraint : Some ( constraint) ,
31+ }
32+ }
33+
34+ /// Start tracking all accesses and mutations into a constraint.
35+ #[ inline]
36+ fn track_mut_with < ' a > (
37+ & ' a mut self ,
38+ constraint : & ' a Constraint < Self > ,
39+ ) -> TrackedMut < ' a , Self > {
40+ TrackedMut {
41+ value : self ,
42+ constraint : Some ( constraint) ,
43+ }
44+ }
45+
46+ /// Whether this value fulfills the given constraints.
47+ ///
48+ /// Such constraints can be generated with `track_with` or `track_mut_with`.
49+ fn valid ( & self , constraint : & Constraint < Self > ) -> bool ;
2450}
2551
2652/// Non-exposed parts of the `Track` trait.
@@ -34,11 +60,8 @@ pub trait Trackable: 'static {
3460 /// The mutable tracked API surface of this type.
3561 type SurfaceMut : for < ' a > Family < ' a > ;
3662
37- /// Whether an instance fulfills the given constraint.
38- fn valid ( & self , constraint : & Constraint < Self :: Call > ) -> bool ;
39-
4063 /// Replay mutations to the value.
41- fn replay ( & mut self , constraint : & Constraint < Self :: Call > ) ;
64+ fn replay ( & mut self , constraint : & Constraint < Self > ) ;
4265
4366 /// Access the immutable surface from a `Tracked`.
4467 fn surface_ref < ' a , ' t > (
79102 ///
80103 /// Starts out as `None` and is set to a stack-stored constraint in the
81104 /// preamble of memoized functions.
82- pub ( crate ) constraint : Option < & ' a Constraint < T :: Call > > ,
105+ pub ( crate ) constraint : Option < & ' a Constraint < T > > ,
83106}
84107
85108// The type `Tracked<T>` automatically dereferences to T's generated surface
@@ -136,7 +159,7 @@ where
136159 ///
137160 /// Starts out as `None` and is set to a stack-stored constraint in the
138161 /// preamble of memoized functions.
139- pub ( crate ) constraint : Option < & ' a Constraint < T :: Call > > ,
162+ pub ( crate ) constraint : Option < & ' a Constraint < T > > ,
140163}
141164
142165impl < ' a , T > TrackedMut < ' a , T >
@@ -214,7 +237,7 @@ where
214237
215238/// Destructure a `Tracked<_>` into its parts.
216239#[ inline]
217- pub fn to_parts_ref < T > ( tracked : Tracked < T > ) -> ( & T , Option < & Constraint < T :: Call > > )
240+ pub fn to_parts_ref < T > ( tracked : Tracked < T > ) -> ( & T , Option < & Constraint < T > > )
218241where
219242 T : Track + ?Sized ,
220243{
@@ -225,7 +248,7 @@ where
225248#[ inline]
226249pub fn to_parts_mut_ref < ' a , T > (
227250 tracked : & ' a TrackedMut < T > ,
228- ) -> ( & ' a T , Option < & ' a Constraint < T :: Call > > )
251+ ) -> ( & ' a T , Option < & ' a Constraint < T > > )
229252where
230253 T : Track + ?Sized ,
231254{
@@ -236,7 +259,7 @@ where
236259#[ inline]
237260pub fn to_parts_mut_mut < ' a , T > (
238261 tracked : & ' a mut TrackedMut < T > ,
239- ) -> ( & ' a mut T , Option < & ' a Constraint < T :: Call > > )
262+ ) -> ( & ' a mut T , Option < & ' a Constraint < T > > )
240263where
241264 T : Track + ?Sized ,
242265{
0 commit comments