cow_struct 0.0.1

Derive a struct with clone-on-write fields
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 5.64 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 268.48 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 4s Average build duration of successful builds.
  • all releases: 4s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • lu-zero

derive CowStruct

This crate consists in a procedural macro derive that provides a struct that is Cow and the impl to create one from the target struct.

Usage

    use cow_struct::CowStruct;

    #[derive(Debug, Default, CowStruct)]
    struct A {
        a: LargeStruct,
        b: OtherLargeStruct,
        c: AnotherOne,
        ...
        z: YetAnother,
    }

    fn evaluation(cfg: &Config, state: &mut CowA) -> usize { ... }

    fn foo() {
        // original struct
        let a = A::new();

        let mut val = 0;
        // similar struct, with all the fields set as Cow::Borrowed from a;
        let mut cow = a.to_cow();
        let mut cow_out = cow.to_cow();
        let mut v_max = usize::min();
        for cfg in inputs() {
            // it is going to change cow, a remains untouched
            let val = evaluation(cfg, &mut cow);

            // let's pick the best candidate
            for candidate in candidates_b(val) {
                let mut cow2 = cow.to_cow();
                let v = evaluation_b(candidate, &mut cow2);
                if v > v_max {
                    v_max = v;
                    cow_out = cow2;
                }
            }
        }
    }