behavior/actor/
creation.rs1use core::marker::PhantomData;
4
5use super::addressing::Address;
6use crate::next::Never;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum CreationKind<N> {
11 Birth,
13 ReplacementIncarnation {
15 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#[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
58pub trait BirthMode {
60 type Child;
61}
62
63#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
65pub struct NoBirths;
66
67impl BirthMode for NoBirths {
68 type Child = Never;
69}
70
71#[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}