reactive_graph_model_core/reactive_graph/core/
action.rs1#![allow(dead_code, unused)]
5#![cfg_attr(rustfmt, rustfmt_skip)]
6
7#[cfg_attr(rustfmt, rustfmt_skip)]
9pub const ACTION_NAMESPACE: &str = "reactive_graph::core::Action";
10
11pub static ACTION: std::sync::LazyLock<reactive_graph_graph::ComponentTypeId> = std::sync::LazyLock::new(||
18std::str::FromStr::from_str(ACTION_NAMESPACE).unwrap());
19
20#[allow(non_camel_case_types)]
22#[derive(Debug, PartialEq, PartialOrd, Eq, Hash, Clone)]
23pub enum ActionProperties {
24
25 TRIGGER,
36}
37impl ActionProperties {
38 pub fn len() -> usize {
39 1usize
40 }
41
42 pub fn property_types() -> reactive_graph_graph::PropertyTypes {
43 let property_types = reactive_graph_graph::PropertyTypes::new();
44 property_types.push(ActionProperties::TRIGGER);
45 property_types
46 }
47}
48
49impl AsRef<str> for ActionProperties {
50 #[inline]
51 fn as_ref(&self) -> &str {
52 match *self {
53 ActionProperties::TRIGGER => "trigger",
54 }
55 }
56}
57
58impl From<ActionProperties> for &'static str {
59 #[inline]
60 fn from(properties: ActionProperties) -> &'static str {
61 match properties {
62 ActionProperties::TRIGGER => "trigger",
63 }
64 }
65}
66
67impl From<ActionProperties> for String {
68 #[inline]
69 fn from(properties: ActionProperties) -> String {
70 match properties {
71 ActionProperties::TRIGGER => "trigger".to_owned(),
72 }
73 }
74}
75
76impl From<ActionProperties> for reactive_graph_graph::PropertyType {
77 #[inline]
78 fn from(properties: ActionProperties) -> reactive_graph_graph::PropertyType {
79 match properties {
80 ActionProperties::TRIGGER => {
81 reactive_graph_graph::PropertyType::new_with_all(
82 "trigger",
83 "On receiving a boolean trigger the action will be executed",
84 reactive_graph_graph::DataType::Bool,
85 reactive_graph_graph::SocketType::Input,
86 reactive_graph_graph::Mutability::Mutable,
87 reactive_graph_graph::Extensions::new(),
88 )
89 }
90 }
91 }
92}
93
94pub struct ActionPropertiesIterator(Option<ActionProperties>);
95
96impl ActionProperties {
97 pub fn into_iter() -> ActionPropertiesIterator {
98 ActionPropertiesIterator(None)
99 }
100}
101
102impl Iterator for ActionPropertiesIterator {
103 type Item = ActionProperties;
104 fn next(&mut self) -> Option<Self::Item> {
105 self.0 = match self.0 {
106 None => Some(ActionProperties::TRIGGER),
107 Some(ActionProperties::TRIGGER) => None,
108 };
109 self.0.clone()
110 }
111}
112
113impl IntoIterator for ActionProperties {
114 type Item = ActionProperties;
115 type IntoIter = ActionPropertiesIterator;
116 fn into_iter(self) -> Self::IntoIter {
117 ActionPropertiesIterator(None)
118 }
119}
120
121impl core::fmt::Display for ActionProperties {
122 fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
123 match *self {
124 ActionProperties::TRIGGER => core::fmt::Display::fmt("trigger", f),
125 }
126 }
127}
128
129pub static ACTION_EXTENSIONS: std::sync::LazyLock<reactive_graph_graph::Extensions> = std::sync::LazyLock::new(||
131{ reactive_graph_graph::Extensions::new() });
132
133pub static ACTION_TYPE: std::sync::LazyLock<reactive_graph_graph::Component> = std::sync::LazyLock::new(||
134{
135 reactive_graph_graph::Component::builder()
136 .ty(core::ops::Deref::deref(&ACTION))
137 .description("An action can be triggered")
138 .properties(ActionProperties::property_types())
139 .build()
140});
141
142pub trait Action {
161
162 fn trigger(&self) -> bool;
173
174 fn set_trigger(&mut self, trigger: bool);
185}