o3 0.62.0

shared-nothing primitives
Documentation
//! Fixed-capacity sets that retain their ordering through every insertion.

use crate::depot::array::{self, copy};

/// An ordered inline set with no allocation or drop glue.
#[repr(transparent)]
pub struct Set<T: Copy, const N: usize> {
    prefix: copy::Vec<T, N>,
}

/// A rejected set member and the exact observed conflict or capacity.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Error<T> {
    Duplicate { value: T, existing: T },
    Full { value: T, capacity: usize },
}

impl<T: Copy + Ord, const N: usize> Default for Set<T, N> {
    fn default() -> Self {
        Self::new()
    }
}

impl<T: Copy + Ord, const N: usize> Set<T, N> {
    pub const fn new() -> Self {
        Self {
            prefix: copy::Vec::new(),
        }
    }

    /// Searches once and consumes the resulting position in this same owner.
    pub fn try_insert(&mut self, value: T) -> Result<(), Error<T>> {
        array::raw::ordered(&mut self.prefix, value)
    }
}