conv_mel/
bool.rs

1use melodium_core::*;
2use melodium_macro::{check, mel_function, mel_treatment};
3
4/// Turns `bool` stream into `void` one.
5#[mel_treatment(
6    input value Stream<bool>
7    output iter Stream<void>
8)]
9pub async fn to_void() {
10    while let Ok(values) = value.recv_bool().await {
11        check!(iter.send_void(vec![(); values.len()]).await)
12    }
13}
14
15/// Turns `bool` into `Vec<byte>`.
16///
17/// ℹ️ A `bool` always corresponds to one `byte`, being `0` if `false` and `1` if `true`.
18#[mel_function]
19pub fn to_byte(value: bool) -> Vec<byte> {
20    vec![match value {
21        true => 1,
22        false => 0,
23    }]
24}
25
26/// Turns `bool` stream into `byte` one.
27///
28/// Each `bool` gets converted into `Vec<byte>`, with each vector containing the `byte` of the former scalar `bool` it represents.
29///
30/// ℹ️ A `bool` always corresponds to one `byte`, being `0` if `false` and `1` if `true`.
31#[mel_treatment(
32    input value Stream<bool>
33    output data Stream<Vec<byte>>
34)]
35pub async fn to_byte() {
36    while let Ok(values) = value.recv_bool().await {
37        check!(
38            data.send_vec_byte(
39                values
40                    .into_iter()
41                    .map(|val| vec![match val {
42                        true => 1,
43                        false => 0,
44                    }])
45                    .collect()
46            )
47            .await
48        )
49    }
50}