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::verdict::Never;
7
8/// Behavior-owned provenance for a staged fresh actor creation request.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum CreationKind {
11    /// An initial or ordinary later birth.
12    Birth,
13    /// A fresh successor incarnation requested by a replacement protocol.
14    ReplacementIncarnation,
15}
16
17/// A staged request to establish a fresh child at a creator-local nonce.
18///
19/// The nonce is a routing and correlation key, not an actor identity or proof
20/// of freshness. Creation and its [`CreationKind`] become runtime facts only
21/// after an interpreter successfully installs the fresh actor and commits the
22/// child binding. Replacement at an existing address is deliberately absent;
23/// stable identity is derived with a proxy actor.
24#[derive(Debug, Clone, PartialEq, Eq)]
25pub struct Create<A: Address, New> {
26    pub nonce: A::Nonce,
27    pub child: New,
28    pub kind: CreationKind,
29}
30
31impl<A: Address, New> Create<A, New> {
32    #[must_use]
33    pub const fn birth(nonce: A::Nonce, child: New) -> Self {
34        Self {
35            nonce,
36            child,
37            kind: CreationKind::Birth,
38        }
39    }
40
41    #[must_use]
42    pub const fn replacement_incarnation(nonce: A::Nonce, child: New) -> Self {
43        Self {
44            nonce,
45            child,
46            kind: CreationKind::ReplacementIncarnation,
47        }
48    }
49}
50
51/// A type-level description of a behavior's creation capability.
52pub trait BirthMode {
53    type Child;
54}
55
56/// This behavior cannot emit child births.
57#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
58pub struct NoBirths;
59
60impl BirthMode for NoBirths {
61    type Child = Never;
62}
63
64/// This behavior may emit births of `C`.
65#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
66pub struct Births<C>(PhantomData<fn() -> C>);
67
68impl<C> BirthMode for Births<C> {
69    type Child = C;
70}