ops_mel/
bool.rs

1use melodium_core::*;
2use melodium_macro::{check, mel_function, mel_treatment};
3
4/// Return whether `a` is equal to `b`
5#[mel_function]
6pub fn equal(a: bool, b: bool) -> bool {
7    a == b
8}
9
10/// Return whether `a` is different `b`
11#[mel_function]
12pub fn not_equal(a: bool, b: bool) -> bool {
13    a != b
14}
15
16/// Determine whether `a` is equal to `b`
17#[mel_treatment(
18    input a Stream<bool>
19    input b Stream<bool>
20    output result Stream<bool>
21)]
22pub async fn equal() {
23    while let (Ok(a), Ok(b)) = (a.recv_one_bool().await, b.recv_one_bool().await) {
24        check!(result.send_one_bool(a == b).await)
25    }
26}
27
28/// Determine whether `a` is different from `b`
29#[mel_treatment(
30    input a Stream<bool>
31    input b Stream<bool>
32    output result Stream<bool>
33)]
34pub async fn not_equal() {
35    while let (Ok(a), Ok(b)) = (a.recv_one_bool().await, b.recv_one_bool().await) {
36        check!(result.send_one_bool(a != b).await)
37    }
38}
39
40/// Makes _and_ ⋀ binary operation on `bool`
41#[mel_function]
42pub fn and(a: bool, b: bool) -> bool {
43    a & b
44}
45
46/// Makes _or_ ⋁ binary operation on `bool`
47#[mel_function]
48pub fn or(a: bool, b: bool) -> bool {
49    a | b
50}
51
52/// Makes _xor_ ⊕ binary operation on `bool`
53#[mel_function]
54pub fn xor(a: bool, b: bool) -> bool {
55    a ^ b
56}
57
58/// Makes _not_ ¬ binary operation on `bool`
59#[mel_function]
60pub fn not(val: bool) -> bool {
61    !val
62}
63
64/// Makes _and_ ⋀ binary operation on `bool`
65#[mel_treatment(
66    input a Stream<bool>
67    input b Stream<bool>
68    output result Stream<bool>
69)]
70pub async fn and() {
71    while let (Ok(a), Ok(b)) = (a.recv_one_bool().await, b.recv_one_bool().await) {
72        check!(result.send_one_bool(a & b).await)
73    }
74}
75
76/// Makes _or_ ⋁ binary operation on `bool`
77#[mel_treatment(
78    input a Stream<bool>
79    input b Stream<bool>
80    output result Stream<bool>
81)]
82pub async fn or() {
83    while let (Ok(a), Ok(b)) = (a.recv_one_bool().await, b.recv_one_bool().await) {
84        check!(result.send_one_bool(a | b).await)
85    }
86}
87
88/// Makes _xor_ ⊕ binary operation on `bool`
89#[mel_treatment(
90    input a Stream<bool>
91    input b Stream<bool>
92    output result Stream<bool>
93)]
94pub async fn xor() {
95    while let (Ok(a), Ok(b)) = (a.recv_one_bool().await, b.recv_one_bool().await) {
96        check!(result.send_one_bool(a ^ b).await)
97    }
98}
99
100/// Makes _not_ ¬ binary operation on `bool`
101#[mel_treatment(
102    input value Stream<bool>
103    output not Stream<bool>
104)]
105pub async fn not() {
106    while let Ok(values) = value.recv_bool().await {
107        check!(
108            not.send_bool(values.into_iter().map(|v| !v).collect())
109                .await
110        )
111    }
112}