lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

states.rs (3525B)


      1 use super::Error;
      2 use wasm_bindgen::prelude::*;
      3 
      4 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
      5 #[wasm_bindgen]
      6 pub enum SatisfactionClass {
      7     Accepted,
      8     Delivered,
      9 }
     10 impl From<radroots_transport::policy::SatisfactionClass> for SatisfactionClass {
     11     fn from(value: radroots_transport::policy::SatisfactionClass) -> Self {
     12         match value {
     13             radroots_transport::policy::SatisfactionClass::Accepted => Self::Accepted,
     14             radroots_transport::policy::SatisfactionClass::Delivered => Self::Delivered,
     15         }
     16     }
     17 }
     18 
     19 // These are generated-language representations, not another state machine.
     20 // A future source state refuses projection instead of gaining a default.
     21 macro_rules! bridge {
     22     ($name:ident, $native:path, [$($variant:ident),+ $(,)?]) => {
     23         #[derive(Clone, Copy, Debug, Eq, PartialEq)]
     24         #[wasm_bindgen]
     25         pub enum $name { $($variant),+ }
     26         impl TryFrom<$native> for $name {
     27             type Error = Error;
     28             fn try_from(value: $native) -> Result<Self, Error> {
     29                 use $native as Native;
     30                 match value {
     31                     $(Native::$variant => Ok(Self::$variant),)+
     32                     _ => Err(Error::UnsupportedState { axis: stringify!($name).to_owned(), operation_id: None, signer_rejection: None }),
     33                 }
     34             }
     35         }
     36     };
     37 }
     38 bridge!(
     39     Admission,
     40     radroots_execution::Admission,
     41     [NotAdmitted, Confirmed, Unknown]
     42 );
     43 bridge!(
     44     BusinessInstallation,
     45     radroots_execution::BusinessInstallation,
     46     [NotApplicable, NotInstalled, Installed, Uncertain]
     47 );
     48 bridge!(
     49     Issuance,
     50     radroots_execution::Issuance,
     51     [None, Pending, Obtained, Unknown, ProvablyUnissued]
     52 );
     53 bridge!(
     54     Delivery,
     55     radroots_execution::Delivery,
     56     [NotStarted, Pending, Observed, Unknown]
     57 );
     58 bridge!(
     59     WaitTermination,
     60     radroots_execution::WaitTermination,
     61     [Returned, Cancelled, DeadlineExceeded, ClientClosed]
     62 );
     63 bridge!(
     64     RecoveryRequirement,
     65     radroots_execution::RecoveryRequirement,
     66     [
     67         ContinueOriginalOperation,
     68         ReconcileIssuance,
     69         InstallObtainedEvidence,
     70         ResumeDelivery,
     71         ManualReconciliation
     72     ]
     73 );
     74 bridge!(
     75     TargetObservation,
     76     radroots_execution::TargetObservation,
     77     [
     78         Accepted,
     79         Rejected,
     80         TimedOut,
     81         Disconnected,
     82         Unknown,
     83         NotAttempted
     84     ]
     85 );
     86 bridge!(
     87     ArtifactRole,
     88     radroots_protocol::intent::ArtifactRole,
     89     [PublicEvent, BusinessSeal, GiftWrap]
     90 );
     91 bridge!(
     92     OperationKind,
     93     radroots_execution::OperationKind,
     94     [Chat, Listing]
     95 );
     96 
     97 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
     98 #[wasm_bindgen]
     99 pub enum StartMode {
    100     LocalOnly,
    101     Online,
    102 }
    103 impl From<StartMode> for crate::StartMode {
    104     fn from(value: StartMode) -> Self {
    105         match value {
    106             StartMode::LocalOnly => Self::LocalOnly,
    107             StartMode::Online => Self::Online,
    108         }
    109     }
    110 }
    111 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
    112 #[wasm_bindgen]
    113 pub enum SessionState {
    114     Ready,
    115     Starting,
    116     Running,
    117     Closing,
    118     Closed,
    119 }
    120 impl From<crate::SessionState> for SessionState {
    121     fn from(value: crate::SessionState) -> Self {
    122         match value {
    123             crate::SessionState::Ready => Self::Ready,
    124             crate::SessionState::Starting => Self::Starting,
    125             crate::SessionState::Running => Self::Running,
    126             crate::SessionState::Closing => Self::Closing,
    127             crate::SessionState::Closed => Self::Closed,
    128         }
    129     }
    130 }