o3 0.60.0

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

use crate::{depot::arena::slab::key, 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<Tag = (), const MAX: u32 = { u32::MAX }> = (
    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 _: () = {
    let _: [(); mem::size_of::<Error>()] = [(); 2 * mem::size_of::<u64>()];
    let _: [(); mem::size_of::<Option<Error>>()] = [(); mem::size_of::<Error>()];
    let _: [(); size_of::<Stale>()] = [(); size_of::<Error>()];
    let _: [(); size_of::<Option<Stale>>()] = [(); size_of::<Stale>()];
};