2 releases

0.1.1 Sep 13, 2023
0.1.0 Sep 13, 2023

#7 in #tracked

Download history 9/week @ 2024-02-17 19/week @ 2024-02-24 3/week @ 2024-03-02 5/week @ 2024-03-09 1/week @ 2024-03-16 30/week @ 2024-03-30 11/week @ 2024-04-06 50/week @ 2024-04-13

91 downloads per month
Used in trackr

MIT license

6KB
125 lines

Trackr

Simple derive-based approach to track modifications of a structure in a flag set, which is provided by the bitflags create

Example:

// Derive trackr::Tracked here
#[derive(Tracked, Default)]
pub struct Sample {
    // Flag field has to be marked, It's always `StructName`Flags
    #[track(flag)]
    tracker_flags: SampleFlags,
    // Private field, with tracker methods marked as public
    #[track(pub_)]
    a: u8,
    // Private field, with private tracker methods
    b: String,
    // Public field, with public tracker methods
    pub c: Vec<usize>,
    // Skip this field for tracking
    #[track(skip)]
    pub d: u32,
}

Usage

Tracked fields are accesible via the 'field'_mut(), which yields a TrackedField struct, which holds a mutable reference to the field and the flag and offers mutable ways to update the value and setting the changed flag in the background. The un-forced like set operations check If the value was changed, thus requiring PartialEq implemented for the type. However there are also forced variants like forced_set which set the changed flag regard.

Dependencies

~0.7–1.1MB
~26K SLoC