Skip to main content

behavior/transition/
actions.rs

1//! The explicit result of one actor behavior transition.
2
3use super::sending::SendAlgebra;
4use crate::Exit;
5use crate::actor::{Address, BirthMode, Create};
6use crate::verdict::{Never, Step};
7
8pub type Become<A, Ph = Never> = Step<Ph, Exit<A>>;
9
10/// Bombay's typed realization of the actor transition effects: communications,
11/// fresh actor creation, and next behavior or termination.
12///
13/// An interpreter installs every fresh actor in `creates` before interpreting
14/// any ordinary delivery or [`crate::ServiceSends`] request in `sends` from this
15/// value. Creation order is vector order, and each concrete send lane retains
16/// its own order; this contract does not impose an order between independent
17/// lanes of a [`crate::SendProduct`]. Constructing a value remains pure.
18pub struct Actions<A: Address, Ph, Sends, Birth: BirthMode> {
19    pub sends: Sends,
20    pub creates: Vec<Create<A, Birth::Child>>,
21    pub become_: Become<A, Ph>,
22}
23
24impl<A: Address, Ph, Sends: SendAlgebra, Birth: BirthMode> Actions<A, Ph, Sends, Birth> {
25    #[must_use]
26    pub fn just(become_: Become<A, Ph>) -> Self {
27        Self {
28            sends: Sends::empty(),
29            creates: Vec::new(),
30            become_,
31        }
32    }
33
34    #[must_use]
35    pub fn cont() -> Self {
36        Self::just(Step::Continue)
37    }
38    #[must_use]
39    pub fn stop(exit: Exit<A>) -> Self {
40        Self::just(Step::Stop(exit))
41    }
42    #[must_use]
43    pub fn goto(phase: Ph) -> Self {
44        Self::just(Step::Goto(phase))
45    }
46}
47
48pub type Acted<A, Ph, Sends, Birth, E> = Result<Actions<A, Ph, Sends, Birth>, E>;