pub struct Tracker { inner: T, dirty: bool, } /// Tracks changes to an inner value T. Any change using `set` will cause the /// tracker to be marked as dirty. impl Tracker { pub fn new(inner: T) -> Self { Self { inner, dirty: true } } pub fn get(&self) -> &T { &self.inner } pub fn get_mut(&mut self) -> &mut T { self.dirty = true; &mut self.inner } pub fn set(&mut self, value: T) { self.dirty = true; self.inner = value; } pub fn is_dirty(&self) -> bool { self.dirty } /// Marks the tracker as clean. pub fn reset(&mut self) { self.dirty = false; } } impl Default for Tracker { fn default() -> Self { Self::new(T::default()) } }