bugadani / Slots

Fixed size data structure with constant-time operations.
MIT License
2 stars 1 forks source link

A key created by a Slots instance can be used to access an other #4

Closed bugadani closed 4 years ago

bugadani commented 4 years ago

See this test case provided by @chrysn

#[test]
fn use_across_slots() {
    let mut a: Slots<u8, U4> = Slots::new();
    let mut b: Slots<u8, U4> = Slots::new();

    let k = a.store(5).expect("There should be room");

    b.take(k);
}
chrysn commented 4 years ago

Some possible approaches (just to have them documented and avoid duplication of work):

bugadani commented 4 years ago

Fortunately, in Rust it is possible to turn on and off library features. I'm considering giving each Slots instance a unique ID that is inherited by its keys. In release builds this protection can be turned off (probably done by default), or re-enabled through configuration.

Not an elegant solution, but simple enough to implement.