pub trait ThinSentinel {
    fn thin_sentinel_zero() -> Self;
    fn thin_sentinel_one() -> Self;
}
Expand description

ThinMap and ThinSet require two sepcial values to denote either an empty or a removed element. This does NOT preclude these elements from being stored in the map/set.

ThinSentinel is already implemented for all the primitives, so if you’re just using those, there is nothing to do.

It’s generally difficult to implement ThinSentinel if the element requires a Drop implementation. ThinMap/ThinSet have not been tested with such keys/elements. The real requirement for this is that Drop should be no-op for the sentinel values.

Here is an example of a custom implementation:

use thincollections::thin_set::ThinSet;
use thincollections::thin_sentinel::ThinSentinel;

#[derive(Hash, Eq, PartialEq, Debug)]
struct Color {
    r: u8, g: u8, b: u8
}

impl ThinSentinel for Color {
    fn thin_sentinel_zero() -> Self {
        Color {r: 0, g: 0, b: 0}
    }

    fn thin_sentinel_one() -> Self {
        Color {r : 0, g: 0, b: 1}
    }
}

let mut colors = ThinSet::new();

colors.insert(Color { r: 255, g: 255, b: 255 });
colors.insert(Color { r: 255, g: 255, b: 0 });
colors.insert(Color { r: 255, g: 0, b: 255 });
colors.insert(Color { r: 0, g: 255, b: 255 });
colors.insert(Color { r: 0, g: 0, b: 0 }); // no trouble storing a sentinel!

// Use derived implementation to print the colors.
for x in &colors {
    println!("{:?}", x);
}

Required Methods

Implementations on Foreign Types

Implementors