Skip to main content

MemberState

Enum MemberState 

Source
#[non_exhaustive]
pub enum MemberState { Reserved, Provisioned, Active, Cancelled, Suspended, Removed, }
Expand description

The state of a tenant’s membership of a node.

The text form is the lowercase name (reserved, provisioned, active, cancelled, suspended, removed), used by Display, FromStr and serde. Parsing is strict: any other text, including another case, is refused. A reader that must survive a state it does not know, such as the gate reading the directory, uses DirectoryMemberState instead.

The transitions are:

FromTo
(none), removed, cancelledreserved (redemption; a returning key gets the next generation)
reservedprovisioned, cancelled
provisionedactive
provisioned, activesuspended
suspendedthe state it remembered (resume), removed

Three predicates name the sets of states the node acts on, so that every component decides them in one place: holds_slot (capacity), may_provision (repair and the reconciler) and is_listed (the gate’s directory and the unsigned profile read).

§Examples

use stratum_node_core::MemberState;

let state: MemberState = "suspended".parse()?;
assert_eq!(state, MemberState::Suspended);
assert_eq!(state.to_string(), "suspended");
assert!(state.holds_slot());
assert!(!state.may_provision());
assert!(state.is_listed());
assert!(!MemberState::Removed.holds_slot());
assert!("Active".parse::<MemberState>().is_err());

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Reserved

The invitation was consumed and a slot is held; the pod is not yet confirmed created.

§

Provisioned

The pod server created the pod.

§

Active

The owner stated that a read and a write to their pod worked.

§

Cancelled

The administrator cancelled a reserved member; no slot is held.

§

Suspended

The administrator stopped this member. The membership remembers whether it was provisioned or active, holds its slot, and every signed request by or to the member is refused.

§

Removed

The administrator ended this membership. No slot is held; the pod data stays on disk until it is purged.

Implementations§

Source§

impl MemberState

Source

pub const ALL: [Self; 6]

Every state, in declaration order.

Tests and the store iterate this list to check that a rule written elsewhere, such as an SQL predicate, agrees with the predicates here for every state.

§Examples
use stratum_node_core::MemberState;

let slot_states: Vec<&str> = MemberState::ALL
    .iter()
    .filter(|s| s.holds_slot())
    .map(|s| s.as_str())
    .collect();
assert_eq!(slot_states, ["reserved", "provisioned", "active", "suspended"]);
Source

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

Returns the lowercase name.

§Examples
use stratum_node_core::MemberState;

assert_eq!(MemberState::Removed.as_str(), "removed");
Source

pub fn holds_slot(self) -> bool

Returns true for the states that count against the node’s tenant capacity: reserved, provisioned, active and suspended.

This is the one definition of capacity. The store builds its SQL count from it.

§Examples
use stratum_node_core::MemberState;

assert!(MemberState::Suspended.holds_slot());
assert!(!MemberState::Cancelled.holds_slot());
assert!(!MemberState::Removed.holds_slot());
Source

pub fn may_provision(self) -> bool

Returns true for the states on which provisioning may act: the reconciler, a recorded provisioning failure and an administrator’s repair. Those are reserved, provisioned and active.

This is deliberately not holds_slot: a suspended member holds a slot, but nothing may call the pod server on its behalf, and neither may anything for a removed or cancelled one. Callers test this before any external call.

§Examples
use stratum_node_core::MemberState;

assert!(MemberState::Reserved.may_provision());
assert!(MemberState::Active.may_provision());
assert!(!MemberState::Suspended.may_provision());
assert!(!MemberState::Removed.may_provision());
Source

pub fn is_listed(self) -> bool

Returns true for the states the controller lists in the gate’s member directory: provisioned, active and suspended.

The same set decides whether the gate serves a key’s profile document without a signature. A reserved, cancelled or removed key is absent from the directory, and the gate treats it as a key that was never a member.

§Examples
use stratum_node_core::MemberState;

assert!(MemberState::Suspended.is_listed());
assert!(!MemberState::Reserved.is_listed());
assert!(!MemberState::Removed.is_listed());

Trait Implementations§

Source§

impl Clone for MemberState

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for MemberState

Source§

impl Debug for MemberState

Source§

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

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

impl<'de> Deserialize<'de> for MemberState

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

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

impl Display for MemberState

Source§

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

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

impl Eq for MemberState

Source§

impl From<MemberState> for DirectoryMemberState

Source§

fn from(state: MemberState) -> Self

Converts to this type from the input type.
Source§

impl FromStr for MemberState

Source§

fn from_str(text: &str) -> Result<Self, Self::Err>

Parses the lowercase name exactly; other cases are refused.

Source§

type Err = ParseMemberStateError

The associated error which can be returned from parsing.
Source§

impl Hash for MemberState

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for MemberState

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for MemberState

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for MemberState

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for MemberState

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

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

impl StructuralPartialEq for MemberState

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.