#invariants #representation #cache #repr #parallelism #automatic #min

repr-rs

A library for representation invariants with caching and parallelism support

8 unstable releases (3 breaking)

0.4.0 Nov 28, 2024
0.3.3 Nov 21, 2024
0.2.2 Nov 19, 2024
0.1.2 Nov 18, 2024

#70 in Caching

Download history 766/week @ 2024-11-16 229/week @ 2024-11-23 27/week @ 2024-11-30 25/week @ 2024-12-07

1,047 downloads per month

MPL-2.0 license

40KB
865 lines

repr-rs: Representation Invariants for Rust

A library for representation invariants with support for automatic caching and parallelism.

See https://docs.rs/repr-rs/latest/repr_rs/struct.Repr.html and https://docs.rs/repr-rs/0.3.3/repr_rs/cache/struct.CacheableRepr.html.

use repr_rs::Repr;

#[derive(Debug)]
struct MinMax { min: i32, max: i32 }

let mut repr = Repr::new(
  MinMax { min: 1, max: 5 },
  |mm| mm.min < mm.max,
);
{
  let view = repr.read();
  assert_eq!(1, view.min);
  assert_eq!(5, view.max);
}
repr.write().min = 4;
let view = repr.read();
assert_eq!(4, view.min);
assert_eq!(5, view.max);

Dependencies

~0–5.5MB
~20K SLoC