use core::marker::PhantomData;
use super::addressing::Address;
use crate::next::Never;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CreationKind<N> {
Birth,
ReplacementIncarnation {
replaces: N,
},
}
impl<N> CreationKind<N> {
#[must_use]
pub const fn replacement_of(replaces: N) -> Self {
Self::ReplacementIncarnation { replaces }
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Create<A: Address, New> {
pub nonce: A::Nonce,
pub child: New,
pub kind: CreationKind<A::Nonce>,
}
impl<A: Address, New> Create<A, New> {
#[must_use]
pub const fn new(nonce: A::Nonce, child: New, kind: CreationKind<A::Nonce>) -> Self {
Self { nonce, child, kind }
}
#[must_use]
pub const fn birth(nonce: A::Nonce, child: New) -> Self {
Self::new(nonce, child, CreationKind::Birth)
}
#[must_use]
pub const fn replacement_incarnation(nonce: A::Nonce, replaces: A::Nonce, child: New) -> Self {
Self::new(nonce, child, CreationKind::replacement_of(replaces))
}
}
pub trait BirthMode {
type Child;
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct NoBirths;
impl BirthMode for NoBirths {
type Child = Never;
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct Births<C>(PhantomData<fn() -> C>);
impl<C> BirthMode for Births<C> {
type Child = C;
}