Skip to main content

SessionState

Enum SessionState 

Source
pub enum SessionState {
    Offline,
    Paused,
    Blocked,
    MustClear,
    Waiting,
    Busy,
    Idle,
}
Expand description

The state of a session. The server derives it from facts; no session reports it (01M3QB6CJ1XCQG5B1BVR8AF3B4, 01M41FZQVEF8S2W9RCM4V87C3D). The first state that matches wins, in this order:

  1. offline: the session has no open watch stream. A lead is not offline while it is not gone, also with no watch (01M48VDGQ5KETKPM4G6TKTC2MB). A session in a container is not offline while the keep-alive of the riff daemon comes (01M510MG0CKDXAKF6YJ768K7E8).
  2. paused: the riff is paused, or the repository of the session is paused (01M3XAHZBGSSJB3YX23K88W01K).
  3. blocked: the session said that it cannot go on with no decision, and the block holds (01M41FZPGEK4TNPSM2051W4VMS). A lead with a block is waiting for its person (01M48VDS8RKJS9HG3KSEYGBFGV).
  4. must_clear: it is a worker that must clear its context before its next claim (01M3X9XAK1KPZZVM1AJR2H8DSS).
  5. waiting: each claim of the session waits for the machinery: a verify, a merge, or an item of its Needs: line (01M41FZP9A50CH4A2VX344DW49). Or a lead waits for its person.
  6. busy: it holds a claim. Or it is the lead, and a turn runs.
  7. idle: each other session.
stateDiagram-v2
    [*] --> idle
    idle --> busy: claim
    busy --> waiting: a verify is asked, a merge waits, a need is open
    waiting --> busy: the fact ends
    busy --> blocked: blocked REASON (wakes the lead)
    blocked --> busy: an answer, then a sign of work
    busy --> must_clear: the last release of a worker
    must_clear --> idle: a clear
use riff_core::wire::{Facts, SessionState};

let all = Facts {
    live: true, paused: true, blocked: true, must_clear: true,
    waiting: true, claims: true, lead: false, turn: false,
};
let of = |f: Facts| SessionState::of(&f);
assert_eq!(of(Facts { live: false, ..all }), SessionState::Offline);
assert_eq!(of(all), SessionState::Paused);
let running = Facts { paused: false, ..all };
assert_eq!(of(running), SessionState::Blocked);
let free = Facts { blocked: false, ..running };
assert_eq!(of(free), SessionState::MustClear);
let cleared = Facts { must_clear: false, ..free };
assert_eq!(of(cleared), SessionState::Waiting);
assert_eq!(of(Facts { waiting: false, ..cleared }), SessionState::Busy);
let none = Facts { waiting: false, claims: false, ..cleared };
assert_eq!(of(none), SessionState::Idle);

// A lead: busy in a turn, waiting for its person, idle else.
let lead = Facts { lead: true, ..none };
assert_eq!(of(lead), SessionState::Idle);
assert_eq!(of(Facts { turn: true, ..lead }), SessionState::Busy);
assert_eq!(of(Facts { blocked: true, turn: true, ..lead }), SessionState::Waiting);

assert_eq!(serde_json::to_string(&SessionState::MustClear).unwrap(), r#""must_clear""#);
assert_eq!(SessionState::MustClear.word(), "must clear");
assert_eq!(serde_json::to_string(&SessionState::Waiting).unwrap(), r#""waiting""#);
assert_eq!(SessionState::Blocked.word(), "blocked");

Variants§

§

Offline

§

Paused

§

Blocked

§

MustClear

§

Waiting

§

Busy

§

Idle

Implementations§

Source§

impl SessionState

Source

pub fn of(f: &Facts) -> Self

The state of a session from its facts. A lead has no claims, so its state comes from its turn and its block (01M48VDS8RKJS9HG3KSEYGBFGV).

Source

pub fn word(self) -> &'static str

The word of the state, the same in each command.

Trait Implementations§

Source§

impl Clone for SessionState

Source§

fn clone(&self) -> SessionState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SessionState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SessionState

Source§

fn default() -> SessionState

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for SessionState

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl JsonSchema for SessionState

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for SessionState

Source§

fn eq(&self, other: &SessionState) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for SessionState

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for SessionState

Source§

impl Eq for SessionState

Source§

impl StructuralPartialEq for SessionState

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,