minerva 0.2.0

Causal ordering for distributed systems
use crate::kairos::Kairos;

use super::VersionVector;

/// An event accepted by an [`Ideal`](crate::metis::Ideal): a totally ordered [`Kairos`] identity, the
/// dependency descriptor its gate reads, and an opaque payload.
///
/// `stamp.station_id()` is the *sender*. The dependency type `D` is the *data* a buffer's
/// [`Gate`](crate::metis::Gate) gates on, the gate's [`Gate::Dep`](crate::metis::Gate::Dep) rather than the gate itself, so one event's
/// data can be read by more than one rule. It defaults to [`VersionVector`], the causal
/// descriptor: there `deps.get(sender)` is this event's own sequence number (`>= 1`) and
/// `deps.get(k)` for every other station `k` is how many of `k`'s events the sender had
/// delivered before producing this one, the Birman-Schiper-Stephenson causal-broadcast
/// contract (PRD 0005). A non-causal gate carries a different `D`: the scalar [`Fifo`](crate::metis::Fifo) gate
/// uses a bare `u64` sequence number.
///
/// The buffer never inspects `payload`; it orders solely by `stamp` and gates solely
/// on `deps`, so `T` carries no bounds.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Event<T, D = VersionVector> {
    /// Totally ordered identity, and the sender (`stamp.station_id()`). Breaks ties
    /// among events that are deliverable at the same time.
    pub stamp: Kairos,
    /// The gate's dependency descriptor ([`Gate::Dep`](crate::metis::Gate::Dep)). Causal: a [`VersionVector`]
    /// including this event's own dot at `deps[sender]`. Scalar: the sender's `u64`
    /// sequence number.
    pub deps: D,
    /// Opaque payload, released to the caller in delivery order.
    pub payload: T,
}