logic_mesh/blocks/logic/
not.rs1use uuid::Uuid;
4
5use crate::base::{
6 block::{Block, BlockDesc, BlockProps, BlockState},
7 input::{input_reader::InputReader, Input, InputProps},
8 output::Output,
9};
10
11use libhaystack::val::{kind::HaystackKind, Bool, Value};
12
13use crate::{blocks::InputImpl, blocks::OutputImpl};
14
15#[block]
17#[derive(BlockProps, Debug)]
18#[category = "logic"]
19pub struct Not {
20 #[input(name = "in", kind = "Bool")]
21 pub input: InputImpl,
22 #[output(kind = "Bool")]
23 pub out: OutputImpl,
24}
25
26impl Block for Not {
27 async fn execute(&mut self) {
28 self.read_inputs_until_ready().await;
29
30 if let Some(Value::Bool(a)) = self.input.get_value() {
31 self.out.set(Bool { value: !a.value }.into());
32 }
33 }
34}
35
36#[cfg(test)]
37mod test {
38
39 use crate::{
40 base::block::test_utils::write_block_inputs, base::block::Block, blocks::logic::Not,
41 };
42
43 #[tokio::test]
44 async fn test_not_block() {
45 let mut block = Not::new();
46
47 write_block_inputs(&mut [(&mut block.input, (true).into())]).await;
48
49 block.execute().await;
50 assert_eq!(block.out.value, false.into());
51 }
52}