minerva 0.2.0

Causal ordering for distributed systems
use core::fmt;

/// A display-only borrow of scoped evidence.
///
/// This is the hardened return of [`Scoped::peek`](super::Scoped::peek),
/// carrying the reference for [`Debug`](fmt::Debug) rendering while refusing
/// every door the brand exists to shut.
///
/// It is deliberately *minimal*. It has no [`PartialOrd`] (so a scoped order
/// verdict cannot escape through a display read, the created-order hazard of PRD
/// 0013), no [`Deref`](core::ops::Deref), and no accessor returning the inner
/// reference (which would just relocate the escape). What it *does* offer is
/// exactly what display and diagnostics need: [`Debug`](fmt::Debug), and
/// [`PartialEq`] so two peeks over the same scope can be checked equal. Equality
/// forgets no roster (it is symmetric and total), so it carries none of the
/// order hazard; that asymmetry, equal-but-never-ordered, is the whole point.
#[derive(Clone, Copy)]
pub struct ScopedPeek<'a, T>(&'a T);

impl<'a, T> ScopedPeek<'a, T> {
    pub(in crate::metis::scope) const fn new(value: &'a T) -> Self {
        Self(value)
    }
}

impl<T: fmt::Debug> fmt::Debug for ScopedPeek<'_, T> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.0.fmt(f)
    }
}

impl<T: PartialEq> PartialEq for ScopedPeek<'_, T> {
    fn eq(&self, other: &Self) -> bool {
        self.0 == other.0
    }
}

impl<T: Eq> Eq for ScopedPeek<'_, T> {}