reactive_graph_runtime_model/reactive_graph/runtime/
shutdown.rs1#![allow(dead_code, unused)]
5#![cfg_attr(rustfmt, rustfmt_skip)]
6
7#[cfg_attr(rustfmt, rustfmt_skip)]
9pub const SHUTDOWN_NAMESPACE: &str = "reactive_graph::runtime::Shutdown";
10
11pub static SHUTDOWN: std::sync::LazyLock<reactive_graph_graph::EntityTypeId> = std::sync::LazyLock::new(||
18std::str::FromStr::from_str(SHUTDOWN_NAMESPACE).unwrap());
19
20#[allow(non_camel_case_types)]
22#[derive(Debug, PartialEq, PartialOrd, Eq, Hash, Clone)]
23pub enum ShutdownProperties {
24
25 DELAY,
34
35 LABEL,
46
47 TRIGGER,
58}
59impl ShutdownProperties {
60 pub fn len() -> usize {
61 3usize
62 }
63
64 pub fn property_types() -> reactive_graph_graph::PropertyTypes {
65 let property_types = reactive_graph_graph::PropertyTypes::new();
66 property_types.push(ShutdownProperties::DELAY);
67 property_types.push(ShutdownProperties::LABEL);
68 property_types.push(ShutdownProperties::TRIGGER);
69 property_types
70 }
71}
72
73impl AsRef<str> for ShutdownProperties {
74 #[inline]
75 fn as_ref(&self) -> &str {
76 match *self {
77 ShutdownProperties::DELAY => "delay",
78 ShutdownProperties::LABEL => "label",
79 ShutdownProperties::TRIGGER => "trigger",
80 }
81 }
82}
83
84impl From<ShutdownProperties> for &'static str {
85 #[inline]
86 fn from(properties: ShutdownProperties) -> &'static str {
87 match properties {
88 ShutdownProperties::DELAY => "delay",
89 ShutdownProperties::LABEL => "label",
90 ShutdownProperties::TRIGGER => "trigger",
91 }
92 }
93}
94
95impl From<ShutdownProperties> for String {
96 #[inline]
97 fn from(properties: ShutdownProperties) -> String {
98 match properties {
99 ShutdownProperties::DELAY => "delay".to_owned(),
100 ShutdownProperties::LABEL => "label".to_owned(),
101 ShutdownProperties::TRIGGER => "trigger".to_owned(),
102 }
103 }
104}
105
106impl From<ShutdownProperties> for reactive_graph_graph::PropertyType {
107 #[inline]
108 fn from(properties: ShutdownProperties) -> reactive_graph_graph::PropertyType {
109 match properties {
110 ShutdownProperties::DELAY => {
111 reactive_graph_graph::PropertyType::new_with_all(
112 "delay",
113 "",
114 reactive_graph_graph::DataType::Number,
115 reactive_graph_graph::SocketType::None,
116 reactive_graph_graph::Mutability::Mutable,
117 reactive_graph_graph::Extensions::new(),
118 )
119 }
120 ShutdownProperties::LABEL => {
121 reactive_graph_graph::PropertyType::new_with_all(
122 "label",
123 "Hierarchical path with static segments, named parameters and catch-all parameters",
124 reactive_graph_graph::DataType::String,
125 reactive_graph_graph::SocketType::None,
126 reactive_graph_graph::Mutability::Mutable,
127 reactive_graph_graph::Extensions::new(),
128 )
129 }
130 ShutdownProperties::TRIGGER => {
131 reactive_graph_graph::PropertyType::new_with_all(
132 "trigger",
133 "On receiving a boolean trigger the action will be executed",
134 reactive_graph_graph::DataType::Bool,
135 reactive_graph_graph::SocketType::Input,
136 reactive_graph_graph::Mutability::Mutable,
137 reactive_graph_graph::Extensions::new(),
138 )
139 }
140 }
141 }
142}
143
144pub struct ShutdownPropertiesIterator(Option<ShutdownProperties>);
145
146impl ShutdownProperties {
147 pub fn into_iter() -> ShutdownPropertiesIterator {
148 ShutdownPropertiesIterator(None)
149 }
150}
151
152impl Iterator for ShutdownPropertiesIterator {
153 type Item = ShutdownProperties;
154 fn next(&mut self) -> Option<Self::Item> {
155 self.0 = match self.0 {
156 None => Some(ShutdownProperties::DELAY),
157 Some(ShutdownProperties::DELAY) => Some(ShutdownProperties::LABEL),
158 Some(ShutdownProperties::LABEL) => Some(ShutdownProperties::TRIGGER),
159 Some(ShutdownProperties::TRIGGER) => None,
160 };
161 self.0.clone()
162 }
163}
164
165impl IntoIterator for ShutdownProperties {
166 type Item = ShutdownProperties;
167 type IntoIter = ShutdownPropertiesIterator;
168 fn into_iter(self) -> Self::IntoIter {
169 ShutdownPropertiesIterator(None)
170 }
171}
172
173impl core::fmt::Display for ShutdownProperties {
174 fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
175 match *self {
176 ShutdownProperties::DELAY => core::fmt::Display::fmt("delay", f),
177 ShutdownProperties::LABEL => core::fmt::Display::fmt("label", f),
178 ShutdownProperties::TRIGGER => core::fmt::Display::fmt("trigger", f),
179 }
180 }
181}
182
183pub static SHUTDOWN_COMPONENTS: std::sync::LazyLock<
191 reactive_graph_graph::ComponentTypeIds,
192> = std::sync::LazyLock::new(|| {
193 reactive_graph_graph::ComponentTypeIds::new()
194 .component(
195 std::ops::Deref::deref(
196 &reactive_graph_model_core::reactive_graph::core::action::ACTION,
197 ),
198 )
199 .component(
200 std::ops::Deref::deref(
201 &reactive_graph_model_core::reactive_graph::core::labeled::LABELED,
202 ),
203 )
204});
205
206pub static SHUTDOWN_EXTENSIONS: std::sync::LazyLock<reactive_graph_graph::Extensions> = std::sync::LazyLock::new(||
208{ reactive_graph_graph::Extensions::new() });
209
210pub static SHUTDOWN_TYPE: std::sync::LazyLock<reactive_graph_graph::EntityType> = std::sync::LazyLock::new(||
211{
212 reactive_graph_graph::EntityType::builder()
213 .ty(core::ops::Deref::deref(&SHUTDOWN))
214 .description("Shutting down the runtime")
215 .components(SHUTDOWN_COMPONENTS.clone())
216 .properties(ShutdownProperties::property_types())
217 .extensions(SHUTDOWN_EXTENSIONS.clone())
218 .build()
219});
220
221#[derive(
252 Debug,
253 Clone,
254 PartialEq,
255 Eq,
256 serde::Serialize,
257 serde::Deserialize,
258 typed_builder::TypedBuilder
259)]
260pub struct Shutdown {
261 #[builder(default, setter(into))]
262 pub id: uuid::Uuid,
263
264 pub delay: u64,
273
274 #[builder(setter(into))]
285 pub label: String,
286
287 pub trigger: bool,
298 #[builder(default, setter(into))]
299 pub extensions: reactive_graph_graph::Extensions,
300}
301
302impl Shutdown {
303 pub fn new(delay: u64, label: String, trigger: bool) -> Self {
304 Self {
305 id: uuid::Uuid::new_v4(),
306 delay,
307 label,
308 trigger,
309 extensions: reactive_graph_graph::Extensions::new(),
310 }
311 }
312 pub fn new_with_id(
313 id: uuid::Uuid,
314 delay: u64,
315 label: String,
316 trigger: bool,
317 ) -> Self {
318 Self {
319 id,
320 delay,
321 label,
322 trigger,
323 extensions: reactive_graph_graph::Extensions::new(),
324 }
325 }
326 pub fn new_with_extensions(
327 id: uuid::Uuid,
328 delay: u64,
329 label: String,
330 trigger: bool,
331 extensions: reactive_graph_graph::Extensions,
332 ) -> Self {
333 Self {
334 id,
335 delay,
336 label,
337 trigger,
338 extensions,
339 }
340 }
341
342 pub fn id(&self) -> uuid::Uuid {
343 self.id
344 }
345
346 pub fn delay(&self) -> u64 {
355 self.delay
356 }
357
358 pub fn set_delay(&mut self, delay: u64) {
367 self.delay = delay;
368 }
369
370 pub fn label(&self) -> String {
381 self.label.clone()
382 }
383
384 pub fn set_label(&mut self, label: String) {
395 self.label = label;
396 }
397
398 pub fn trigger(&self) -> bool {
409 self.trigger
410 }
411
412 pub fn set_trigger(&mut self, trigger: bool) {
423 self.trigger = trigger;
424 }
425
426 pub fn properties(&self) -> reactive_graph_graph::PropertyInstances {
427 reactive_graph_graph::PropertyInstances::new()
428 .property(ShutdownProperties::DELAY, self.delay.clone())
429 .property(ShutdownProperties::LABEL, self.label.clone())
430 .property(ShutdownProperties::TRIGGER, self.trigger.clone())
431 }
432
433 pub fn extensions(&self) -> reactive_graph_graph::Extensions {
434 self.extensions.clone()
435 }
436}
437
438impl From<Shutdown> for reactive_graph_graph::EntityInstance {
439 fn from(shutdown: Shutdown) -> Self {
440 reactive_graph_graph::EntityInstance::builder()
441 .ty(std::ops::Deref::deref(&SHUTDOWN))
442 .id(shutdown.id())
443 .components(SHUTDOWN_COMPONENTS.clone())
444 .properties(shutdown.properties())
445 .build()
446 }
447}
448
449impl TryFrom<reactive_graph_graph::EntityInstance> for Shutdown {
450 type Error = ();
451 fn try_from(
452 entity_instance: reactive_graph_graph::EntityInstance,
453 ) -> Result<Self, Self::Error> {
454 Err(())
455 }
456}
457impl reactive_graph_model_core::reactive_graph::core::action::Action for Shutdown {
458
459 fn trigger(&self) -> bool {
470 self.trigger
471 }
472
473 fn set_trigger(&mut self, trigger: bool) {
484 self.trigger = trigger;
485 }
486}
487impl reactive_graph_model_core::reactive_graph::core::labeled::Labeled for Shutdown {
488
489 fn label(&self) -> String {
500 self.label.clone()
501 }
502
503 fn set_label(&mut self, label: String) {
514 self.label = label;
515 }
516}