pub trait ThinSentinel {
    // Required methods
    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§

source§

impl ThinSentinel for i128

source§

impl ThinSentinel for i64

source§

impl<T> ThinSentinel for *const T

source§

impl ThinSentinel for u16

source§

impl ThinSentinel for i32

source§

impl ThinSentinel for isize

source§

impl ThinSentinel for i16

source§

impl ThinSentinel for u128

source§

impl ThinSentinel for TypeId

source§

impl<T> ThinSentinel for *mut T

source§

impl ThinSentinel for f64

source§

impl ThinSentinel for usize

source§

impl ThinSentinel for char

source§

impl ThinSentinel for f32

source§

impl ThinSentinel for u32

source§

impl<T: ThinSentinel, U: ThinSentinel> ThinSentinel for (T, U)

source§

impl ThinSentinel for u64

source§

impl<T: ThinSentinel, U: ThinSentinel, V: ThinSentinel> ThinSentinel for (T, U, V)

source§

impl ThinSentinel for u8

source§

impl ThinSentinel for i8

Implementors§