summaryrefslogtreecommitdiffstats
path: root/src/dirty.rs
blob: fe6e4d16cbc5b4ca73b94b7ca856f4ef5470fecf (plain)
1
2
3
4
5
6
7
8
9
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
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
pub struct DirtyBit(bool);

pub trait Dirtyable {
    fn get_bit(&self) -> &DirtyBit;
    fn get_bit_mut(&mut self) -> &mut DirtyBit;

    fn is_dirty(&self) -> bool {
        self.get_bit().0
    }

    fn set_dirty(&mut self) {
        self.get_bit_mut().0 = true;
    }
    fn set_clean(&mut self) {
        self.get_bit_mut().0 = false;
    }
}


impl DirtyBit {
    pub fn new() -> DirtyBit {
        DirtyBit(false)
    }
}


impl Dirtyable for DirtyBit {
    fn get_bit(&self) -> &DirtyBit {
        self
    }
    fn get_bit_mut(&mut self) -> &mut DirtyBit {
        self
    }
}