Skip to main content

behavior/actor/
creation.rs

1//! Staged fresh-actor creation capabilities.
2
3use core::marker::PhantomData;
4
5use super::addressing::Address;
6use crate::next::Never;
7
8/// Behavior-owned provenance for a staged fresh actor creation request.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum CreationKind<N> {
11    /// An initial or ordinary later birth.
12    Birth,
13    /// A fresh successor incarnation requested by a replacement protocol.
14    ReplacementIncarnation {
15        /// The exact child incarnation this fresh actor is intended to replace.
16        replaces: N,
17    },
18}
19
20impl<N> CreationKind<N> {
21    #[must_use]
22    pub const fn replacement_of(replaces: N) -> Self {
23        Self::ReplacementIncarnation { replaces }
24    }
25}
26
27/// A staged request to establish a fresh child at a creator-local nonce.
28///
29/// The nonce is a routing and correlation key, not an actor identity or proof
30/// of freshness. The kind is Behavior-owned intent; [`crate::CreationResolved`]
31/// is the corresponding committed runtime fact. Replacement at an existing
32/// address is deliberately absent; stable identity is derived with a proxy
33/// actor.
34#[derive(Debug, Clone, PartialEq, Eq)]
35pub struct Create<A: Address, New> {
36    pub nonce: A::Nonce,
37    pub child: New,
38    pub kind: CreationKind<A::Nonce>,
39}
40
41impl<A: Address, New> Create<A, New> {
42    #[must_use]
43    pub const fn new(nonce: A::Nonce, child: New, kind: CreationKind<A::Nonce>) -> Self {
44        Self { nonce, child, kind }
45    }
46
47    #[must_use]
48    pub const fn birth(nonce: A::Nonce, child: New) -> Self {
49        Self::new(nonce, child, CreationKind::Birth)
50    }
51
52    #[must_use]
53    pub const fn replacement_incarnation(nonce: A::Nonce, replaces: A::Nonce, child: New) -> Self {
54        Self::new(nonce, child, CreationKind::replacement_of(replaces))
55    }
56}
57
58/// A type-level description of a behavior's creation capability.
59pub trait BirthMode {
60    type Child;
61}
62
63/// This behavior cannot emit child births.
64#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
65pub struct NoBirths;
66
67impl BirthMode for NoBirths {
68    type Child = Never;
69}
70
71/// This behavior may emit births of `C`.
72#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
73pub struct Births<C>(PhantomData<fn() -> C>);
74
75impl<C> BirthMode for Births<C> {
76    type Child = C;
77}