#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct EndpointId(u64);
impl EndpointId {
pub const fn new(value: u64) -> Self {
Self(value)
}
pub const fn get(self) -> u64 {
self.0
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct LaneId(u32);
impl LaneId {
pub const fn new(value: u32) -> Self {
Self(value)
}
pub const fn get(self) -> u32 {
self.0
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct ConnectionId(u64);
impl ConnectionId {
pub const fn new(value: u64) -> Self {
Self(value)
}
pub const fn get(self) -> u64 {
self.0
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct ConnectionEpoch(u64);
impl ConnectionEpoch {
pub const fn new(value: u64) -> Self {
Self(value)
}
pub const fn get(self) -> u64 {
self.0
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct OperationId(u64);
impl OperationId {
pub const fn new(value: u64) -> Self {
Self(value)
}
pub const fn get(self) -> u64 {
self.0
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct EffectId(u64);
impl EffectId {
pub const fn new(value: u64) -> Self {
Self(value)
}
pub const fn get(self) -> u64 {
self.0
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct MatchKey(u32);
impl MatchKey {
pub const fn new(value: u32) -> Self {
Self(value)
}
pub const fn get(self) -> u32 {
self.0
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct IdentitySeeds {
operation: u64,
effect: u64,
}
impl IdentitySeeds {
pub const ZERO: Self = Self::new(0, 0);
pub const fn new(operation: u64, effect: u64) -> Self {
Self { operation, effect }
}
pub const fn operation(self) -> u64 {
self.operation
}
pub const fn effect(self) -> u64 {
self.effect
}
}
#[derive(Debug)]
pub(crate) struct IdentityGenerator {
operation: Option<u64>,
effect: Option<u64>,
}
impl IdentityGenerator {
pub(crate) const fn new(seeds: IdentitySeeds) -> Self {
Self {
operation: Some(seeds.operation()),
effect: Some(seeds.effect()),
}
}
pub(crate) const fn available(&self) -> bool {
self.operation.is_some() && self.effect.is_some()
}
pub(crate) fn take(&mut self) -> Option<(OperationId, EffectId)> {
let operation = self.operation?;
let effect = self.effect?;
self.operation = operation.checked_add(1);
self.effect = effect.checked_add(1);
Some((OperationId::new(operation), EffectId::new(effect)))
}
}