o3 0.59.0

shared-nothing primitives
Documentation
use std::{convert, mem, num::NonZero};

use crate::{
    depot::{arena::slab::key, capacity},
    mem::Rejected,
};

/// The exact key and physical observation that rejected an exclusive lookup.
pub type Error<Tag = (), const MAX: u32 = { u32::MAX }, B = convert::Infallible, R = ()> =
    Rejected<key::Handle<Tag, MAX>, key::Observation<MAX, B, R>>;

/// A bounded identity whose resident state or generation no longer matches.
pub type Stale<'h, Tag = (), const MAX: u32 = { u32::MAX }> = (
    capacity::Key<'h, key::Handle<Tag, MAX>>,
    key::Observation<MAX, convert::Infallible, (), convert::Infallible>,
);

impl<Tag, const MAX: u32, B, R> Error<Tag, MAX, B, R> {
    /// Borrows the rejected identity and observation as diagnostic metadata.
    /// The scalar identity carries no branded handle or reconstruction authority.
    pub fn observation(&self) -> (u32, NonZero<u32>, key::Observation<MAX, &B, &R>) {
        use key::Observation;

        let seen = match *self.error() {
            Observation::Index { capacity } => Observation::Index { capacity },
            Observation::Free { actual } => Observation::Free { actual },
            Observation::Reserved { actual } => Observation::Reserved { actual },
            Observation::Retired {
                actual,
                ref retired,
            } => Observation::Retired { actual, retired },
            Observation::Generation { actual } => Observation::Generation { actual },
            Observation::Busy { actual, ref borrow } => Observation::Busy { actual, borrow },
        };
        let key = self.value();
        (key.index(), key.generation().nonzero(), seen)
    }
}

const _: () = {
    assert!(mem::size_of::<Error>() == 2 * mem::size_of::<u64>());
    assert!(mem::size_of::<Option<Error>>() == mem::size_of::<Error>());
    assert!(size_of::<Stale<'static>>() == size_of::<Error>());
    assert!(size_of::<Option<Stale<'static>>>() == size_of::<Stale<'static>>());
};