pub enum EpisodeState {
Opening,
Open,
Detached,
Closed,
}Expand description
Where an episode is: minted, open, detached from the connection that held it, or closed into the immutable record.
use majordomus_cli::session::EpisodeState;
assert!(EpisodeState::Open.may_move_to(EpisodeState::Closed));
assert!(!EpisodeState::Closed.may_move_to(EpisodeState::Open), "a record is immutable");
assert!(EpisodeState::Open.may_move_to(EpisodeState::Open), "a resume is not a move");
assert!(EpisodeState::Closed.is_final());Variants§
Opening
An identity has been minted and nothing durable has been written yet. It exists so that a crash between minting an id and writing the open record is a state the model can name rather than an episode that never happened.
Open
The open record stands. The worker is here, or was recently.
Detached
The connection that held the episode went away, and the episode did not. A dropped socket is the most ordinary thing that happens to a session; an episode that closed itself on every disconnect would lose the work of every worker whose network hiccuped. It is still resumable, and it is still recoverable if nobody resumes it.
Closed
The immutable record has been published. Terminal, and terminal is the point: the
four records of s-20260909152316-024f all exist because nothing in the previous
representation could say this.
Implementations§
Source§impl EpisodeState
impl EpisodeState
Sourcepub const ALL: [EpisodeState; 4]
pub const ALL: [EpisodeState; 4]
Every state, in the order a reader meets them. The projection of the machine is built from this rather than from a list written a second time somewhere else.
Sourcepub fn may_move_to(self, target: EpisodeState) -> bool
pub fn may_move_to(self, target: EpisodeState) -> bool
May an episode in this state move to target?
The whole transition table, and the only copy of it. Note what the signature does not take: there is no task, no outcome and no policy. A transition of an episode is a fact about the episode.
use majordomus_cli::session::EpisodeState::*;
assert!(Opening.may_move_to(Open));
assert!(Open.may_move_to(Detached) && Detached.may_move_to(Open));
assert!(Open.may_move_to(Closed) && Detached.may_move_to(Closed));
// an episode that never opened cannot be closed into a record of what it did
assert!(!Opening.may_move_to(Closed));
// and nothing leaves the terminal state
for target in [Opening, Open, Detached, Closed] {
assert!(!Closed.may_move_to(target));
}Sourcepub fn is_final(self) -> bool
pub fn is_final(self) -> bool
Is this a state an episode never leaves? True of closed alone, which is what a
store asks before it writes and a reader asks before it waits for a change.
use majordomus_cli::session::EpisodeState;
assert!(EpisodeState::Closed.is_final());
assert!(!EpisodeState::Detached.is_final(), "a detached episode can still be resumed");Sourcepub fn as_str(self) -> &'static str
pub fn as_str(self) -> &'static str
The word as serialised, which is the word every projection of the machine carries
and the word a person reads in session status.
use majordomus_cli::session::EpisodeState;
assert_eq!(EpisodeState::Detached.as_str(), "detached");
assert_eq!(EpisodeState::Closed.as_str(), "closed");Trait Implementations§
Source§impl Clone for EpisodeState
impl Clone for EpisodeState
Source§fn clone(&self) -> EpisodeState
fn clone(&self) -> EpisodeState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for EpisodeState
Source§impl Debug for EpisodeState
impl Debug for EpisodeState
Source§impl<'de> Deserialize<'de> for EpisodeState
impl<'de> Deserialize<'de> for EpisodeState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for EpisodeState
Source§impl Hash for EpisodeState
impl Hash for EpisodeState
Source§impl JsonSchema for EpisodeState
impl JsonSchema for EpisodeState
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl Ord for EpisodeState
impl Ord for EpisodeState
Source§fn cmp(&self, other: &EpisodeState) -> Ordering
fn cmp(&self, other: &EpisodeState) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for EpisodeState
impl PartialEq for EpisodeState
Source§fn eq(&self, other: &EpisodeState) -> bool
fn eq(&self, other: &EpisodeState) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialOrd for EpisodeState
impl PartialOrd for EpisodeState
Source§impl Serialize for EpisodeState
impl Serialize for EpisodeState
impl StructuralPartialEq for EpisodeState
Auto Trait Implementations§
impl Freeze for EpisodeState
impl RefUnwindSafe for EpisodeState
impl Send for EpisodeState
impl Sync for EpisodeState
impl Unpin for EpisodeState
impl UnsafeUnpin for EpisodeState
impl UnwindSafe for EpisodeState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.