1#[doc(hidden)]
7extern crate alloc;
8
9use crate::error::Error;
11use alloc::vec::Vec;
12use alloc::{
13 boxed::Box,
14 string::{String, ToString},
15};
16use bitcode::{Decode, Encode};
17use core::fmt::{Debug, Display};
18#[derive(Debug, Decode, Encode, Clone, Default, Eq, PartialEq, Ord, PartialOrd)]
23pub enum OperationState {
24 Error,
26 #[default]
28 Created,
29 Configured,
31 Inactive,
33 Standby,
35 Active,
37}
38
39impl TryFrom<&str> for OperationState {
40 type Error = Box<dyn core::error::Error + Send + Sync + 'static>;
41
42 fn try_from(
43 value: &str,
44 ) -> core::result::Result<Self, Box<dyn core::error::Error + Send + Sync + 'static>> {
45 let v = value.to_lowercase();
46 match v.as_str() {
47 "created" => Ok(Self::Created),
48 "configured" => Ok(Self::Configured),
49 "inactive" => Ok(Self::Inactive),
50 "standby" => Ok(Self::Standby),
51 "active" => Ok(Self::Active),
52 _ => Err(Error::UnknownOperationState {
53 state: value.to_string(),
54 }
55 .into()),
56 }
57 }
58}
59
60impl Display for OperationState {
61 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
62 match self {
63 Self::Error => write!(f, "Error"),
64 Self::Created => write!(f, "Created"),
65 Self::Configured => write!(f, "Configured"),
66 Self::Inactive => write!(f, "Inactive"),
67 Self::Standby => write!(f, "Standby"),
68 Self::Active => write!(f, "Active"),
69 }
70 }
71}
72#[derive(Debug, Decode, Encode)]
77pub enum Signal {
78 About,
80 Ping {
82 sent: i64,
84 },
85 Shutdown,
87 State {
89 state: Option<OperationState>,
91 },
92}
93#[derive(Debug, Clone)]
98pub enum TaskSignal {
99 #[cfg(feature = "unstable")]
101 RestartLiveliness(String),
102 RestartObservable(String),
104 RestartQueryable(String),
106 RestartSubscriber(String),
108 RestartTimer(String),
110 Shutdown,
112}
113