1use melodium_core::*;
2use melodium_macro::{check, mel_function, mel_treatment};
3
4#[mel_function]
6pub fn equal(a: byte, b: byte) -> bool {
7 a == b
8}
9
10#[mel_function]
12pub fn not_equal(a: byte, b: byte) -> bool {
13 a != b
14}
15
16#[mel_treatment(
18 input a Stream<byte>
19 input b Stream<byte>
20 output result Stream<bool>
21)]
22pub async fn equal() {
23 while let (Ok(a), Ok(b)) = (a.recv_one_byte().await, b.recv_one_byte().await) {
24 check!(result.send_one_bool(a == b).await)
25 }
26}
27
28#[mel_treatment(
30 input a Stream<byte>
31 input b Stream<byte>
32 output result Stream<bool>
33)]
34pub async fn not_equal() {
35 while let (Ok(a), Ok(b)) = (a.recv_one_byte().await, b.recv_one_byte().await) {
36 check!(result.send_one_bool(a != b).await)
37 }
38}
39
40#[mel_function]
42pub fn and(a: byte, b: byte) -> byte {
43 a & b
44}
45
46#[mel_function]
48pub fn or(a: byte, b: byte) -> byte {
49 a | b
50}
51
52#[mel_function]
54pub fn xor(a: byte, b: byte) -> byte {
55 a ^ b
56}
57
58#[mel_function]
60pub fn not(val: byte) -> byte {
61 !val
62}
63
64#[mel_treatment(
66 input a Stream<byte>
67 input b Stream<byte>
68 output result Stream<byte>
69)]
70pub async fn and() {
71 while let (Ok(a), Ok(b)) = (a.recv_one_byte().await, b.recv_one_byte().await) {
72 check!(result.send_one_byte(a & b).await)
73 }
74}
75
76#[mel_treatment(
78 input a Stream<byte>
79 input b Stream<byte>
80 output result Stream<byte>
81)]
82pub async fn or() {
83 while let (Ok(a), Ok(b)) = (a.recv_one_byte().await, b.recv_one_byte().await) {
84 check!(result.send_one_byte(a | b).await)
85 }
86}
87
88#[mel_treatment(
90 input a Stream<byte>
91 input b Stream<byte>
92 output result Stream<byte>
93)]
94pub async fn xor() {
95 while let (Ok(a), Ok(b)) = (a.recv_one_byte().await, b.recv_one_byte().await) {
96 check!(result.send_one_byte(a ^ b).await)
97 }
98}
99
100#[mel_treatment(
102 input value Stream<byte>
103 output not Stream<byte>
104)]
105pub async fn not() {
106 while let Ok(values) = value.recv_byte().await {
107 check!(
108 not.send_byte(values.into_iter().map(|v| !v).collect())
109 .await
110 )
111 }
112}