#dirty #data #marker #buffer #modified #fields #changed

dirtytype

A marker of types being dirty for Rust

7 releases (4 breaking)

0.5.1 Jul 5, 2023
0.5.0 Jul 5, 2023
0.4.1 May 7, 2023
0.3.0 Apr 17, 2023
0.1.0 Apr 14, 2023

#3 in #modified

49 downloads per month

MIT license

4KB
63 lines

dirtytype

This is a library for marking fields as dirty, ie marking them when they are changed.

Example usage

Dirty can be used create a type that stores a copy of data and writes it to some sort of buffer when the data is modified:

# struct Buffer {}
# impl Buffer {
#     fn update<T>(&mut self, value: T) {}
# }
use dirtytype::Dirty;

struct BufferData<T> {
    data: Dirty<T>,
    buffer: Buffer,
}

impl<T: Default + Clone> BufferData<T> {
    fn update(&mut self) {
        self.data.clean(|value| self.buffer.update(value.clone()));
    }
}

No runtime deps