conv_mel/
string.rs

1use melodium_core::*;
2use melodium_macro::{check, mel_function, mel_treatment};
3
4/// Turns `string` stream into `void` one.
5#[mel_treatment(
6    input value Stream<string>
7    output iter Stream<void>
8)]
9pub async fn to_void() {
10    while let Ok(values) = value.recv_string().await {
11        check!(iter.send_void(vec![(); values.len()]).await)
12    }
13}
14
15/// Turns `string` into `Vec<byte>`.
16///
17/// ℹ️ The `Vec<byte>` obtained from a `string` is the UTF-8 representation of it.
18#[mel_function]
19pub fn to_byte(value: string) -> Vec<byte> {
20    value.as_bytes().to_vec()
21}
22
23/// Turns `string` stream into `byte` one.
24///
25/// Each `string` gets converted into `Vec<byte>`, with each vector containing the `byte`s of the former scalar `string` it represents.
26///
27/// ℹ️ The `Vec<byte>` obtained from a `string` is the UTF-8 representation of it.
28#[mel_treatment(
29    input value Stream<string>
30    output data Stream<Vec<byte>>
31)]
32pub async fn to_byte() {
33    while let Ok(values) = value.recv_string().await {
34        check!(
35            data.send_vec_byte(
36                values
37                    .into_iter()
38                    .map(|val| val.as_bytes().to_vec())
39                    .collect()
40            )
41            .await
42        )
43    }
44}