pub struct Rack { /* private fields */ }Expand description
State of the process or a group of logic lines. Acts as a factory for Processor instances.
Shares recording state with the created processors.
Implementations§
Source§impl Rack
impl Rack
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new state
Examples found in repository?
examples/fan_control.rs (line 4)
3fn main() {
4 let mut state = Rack::new().with_recording_enabled();
5 let mut processor = state.processor();
6
7 // Some fan state
8 let mut fan = false;
9
10 // A temperature sensor value
11 let temperature = 31.0;
12
13 processor
14 // a sequence to turn on the fan on if the temperature is above 30 degrees
15 .line("fan_on", temperature)
16 .then(action!("temp_high", |t| (t > 30.0).then_some(())))
17 .then(action!("fan_on", |()| {
18 fan = true;
19 Some(())
20 }));
21 processor
22 // a sequence to turn off the fan if the temperature is below 25 degrees
23 .line("fan_off", temperature)
24 .then(action!("temp_low", |t| (t < 25.0).then_some(())))
25 .then(action!("fan_off", |()| {
26 fan = false;
27 Some(())
28 }));
29
30 state.ingress(&mut processor);
31 println!("{}", state);
32
33 println!("{}", serde_json::to_string_pretty(&state).unwrap());
34}Sourcepub fn ingress(&mut self, processor: &mut Processor)
pub fn ingress(&mut self, processor: &mut Processor)
Record the state of the lines and reset the processor
Examples found in repository?
examples/fan_control.rs (line 30)
3fn main() {
4 let mut state = Rack::new().with_recording_enabled();
5 let mut processor = state.processor();
6
7 // Some fan state
8 let mut fan = false;
9
10 // A temperature sensor value
11 let temperature = 31.0;
12
13 processor
14 // a sequence to turn on the fan on if the temperature is above 30 degrees
15 .line("fan_on", temperature)
16 .then(action!("temp_high", |t| (t > 30.0).then_some(())))
17 .then(action!("fan_on", |()| {
18 fan = true;
19 Some(())
20 }));
21 processor
22 // a sequence to turn off the fan if the temperature is below 25 degrees
23 .line("fan_off", temperature)
24 .then(action!("temp_low", |t| (t < 25.0).then_some(())))
25 .then(action!("fan_off", |()| {
26 fan = false;
27 Some(())
28 }));
29
30 state.ingress(&mut processor);
31 println!("{}", state);
32
33 println!("{}", serde_json::to_string_pretty(&state).unwrap());
34}Sourcepub fn line_state(&self, name: &str) -> Option<&LineState>
pub fn line_state(&self, name: &str) -> Option<&LineState>
Returns the state of the line
Sourcepub fn snapshot_filtered<P>(&self, predicate: P) -> Snapshot
pub fn snapshot_filtered<P>(&self, predicate: P) -> Snapshot
Creates a filtered snapshot of the current state of the lines
Sourcepub fn processor(&self) -> Processor
pub fn processor(&self) -> Processor
Creates a new processor
Examples found in repository?
examples/fan_control.rs (line 5)
3fn main() {
4 let mut state = Rack::new().with_recording_enabled();
5 let mut processor = state.processor();
6
7 // Some fan state
8 let mut fan = false;
9
10 // A temperature sensor value
11 let temperature = 31.0;
12
13 processor
14 // a sequence to turn on the fan on if the temperature is above 30 degrees
15 .line("fan_on", temperature)
16 .then(action!("temp_high", |t| (t > 30.0).then_some(())))
17 .then(action!("fan_on", |()| {
18 fan = true;
19 Some(())
20 }));
21 processor
22 // a sequence to turn off the fan if the temperature is below 25 degrees
23 .line("fan_off", temperature)
24 .then(action!("temp_low", |t| (t < 25.0).then_some(())))
25 .then(action!("fan_off", |()| {
26 fan = false;
27 Some(())
28 }));
29
30 state.ingress(&mut processor);
31 println!("{}", state);
32
33 println!("{}", serde_json::to_string_pretty(&state).unwrap());
34}Sourcepub fn with_recording_enabled(self) -> Self
pub fn with_recording_enabled(self) -> Self
Enables recording for the state
Examples found in repository?
examples/fan_control.rs (line 4)
3fn main() {
4 let mut state = Rack::new().with_recording_enabled();
5 let mut processor = state.processor();
6
7 // Some fan state
8 let mut fan = false;
9
10 // A temperature sensor value
11 let temperature = 31.0;
12
13 processor
14 // a sequence to turn on the fan on if the temperature is above 30 degrees
15 .line("fan_on", temperature)
16 .then(action!("temp_high", |t| (t > 30.0).then_some(())))
17 .then(action!("fan_on", |()| {
18 fan = true;
19 Some(())
20 }));
21 processor
22 // a sequence to turn off the fan if the temperature is below 25 degrees
23 .line("fan_off", temperature)
24 .then(action!("temp_low", |t| (t < 25.0).then_some(())))
25 .then(action!("fan_off", |()| {
26 fan = false;
27 Some(())
28 }));
29
30 state.ingress(&mut processor);
31 println!("{}", state);
32
33 println!("{}", serde_json::to_string_pretty(&state).unwrap());
34}Sourcepub fn set_recording(&mut self, recording: bool)
pub fn set_recording(&mut self, recording: bool)
Sets the recording state for the state
Sourcepub fn is_recording(&self) -> bool
pub fn is_recording(&self) -> bool
Returns true if the rack is recording
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Rack
impl<'de> Deserialize<'de> for Rack
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Rack
impl RefUnwindSafe for Rack
impl Send for Rack
impl Sync for Rack
impl Unpin for Rack
impl UnwindSafe for Rack
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more