std_mel/
conv.rs

1use melodium_core::*;
2use melodium_macro::{check, mel_function, mel_treatment};
3
4/// Turns any data into `void`.
5#[mel_function(
6    generic T ()
7)]
8pub fn to_void(_value: T) -> void {
9    ()
10}
11
12/// Turns any stream into `void` one.
13#[mel_treatment(
14    generic T ()
15    input value Stream<T>
16    output iter Stream<void>
17)]
18pub async fn to_void() {
19    while let Ok(values) = value.recv_many().await {
20        check!(iter.send_many(vec![(); values.len()].into()).await)
21    }
22}
23
24/// Turns data into `Vec<byte>`.
25///
26/// Data element gets converted into `Vec<byte>`, with vector containing the binary form of data it represents.
27///
28/// ℹ️ While this conversion is infaillible, resulting vector may be empty.
29/// Content format and length of vector is totally dependent on data type given, and might not be constant (like for `char` or `string` types).
30
31#[mel_function(
32    generic T ()
33)]
34pub fn to_bytes(value: T) -> Vec<byte> {
35    fn to_bytes(value: T) -> Vec<byte> {
36        match value {
37            Value::Void(_) => Vec::new(),
38            Value::I8(val) => val.to_be_bytes().iter().map(|v| *v).collect(),
39            Value::I16(val) => val.to_be_bytes().iter().map(|v| *v).collect(),
40            Value::I32(val) => val.to_be_bytes().iter().map(|v| *v).collect(),
41            Value::I64(val) => val.to_be_bytes().iter().map(|v| *v).collect(),
42            Value::I128(val) => val.to_be_bytes().iter().map(|v| *v).collect(),
43            Value::U8(val) => val.to_be_bytes().iter().map(|v| *v).collect(),
44            Value::U16(val) => val.to_be_bytes().iter().map(|v| *v).collect(),
45            Value::U32(val) => val.to_be_bytes().iter().map(|v| *v).collect(),
46            Value::U64(val) => val.to_be_bytes().iter().map(|v| *v).collect(),
47            Value::U128(val) => val.to_be_bytes().iter().map(|v| *v).collect(),
48            Value::F32(val) => val.to_be_bytes().iter().map(|v| *v).collect(),
49            Value::F64(val) => val.to_be_bytes().iter().map(|v| *v).collect(),
50            Value::Bool(val) => match val {
51                true => vec![1u8],
52                false => vec![0u8],
53            },
54            Value::Byte(val) => val.to_be_bytes().iter().map(|v| *v).collect(),
55            Value::Char(val) => val.to_string().as_bytes().iter().map(|v| *v).collect(),
56            Value::String(val) => val.as_bytes().iter().map(|v| *v).collect(),
57            Value::Vec(_vals) => Vec::new(),
58            Value::Option(val) => match val {
59                Some(val) => to_bytes(*val),
60                None => Vec::new(),
61            },
62            Value::Data(_) => Vec::new(),
63        }
64    }
65    to_bytes(value)
66}
67
68/// Turns data stream into `Vec<byte>` one.
69///
70/// Each data element gets converted into `Vec<byte>`, with each vector containing the binary form of data it represents.
71///
72/// ℹ️ While this conversion is infaillible, resulting vector may be empty.
73/// Content format and length of each vector is totally dependent on data type given, and might not be constant (like for `char` or `string` types).
74#[mel_treatment(
75    generic T ()
76    input value Stream<T>
77    output data Stream<Vec<byte>>
78)]
79pub async fn to_bytes() {
80    while let Ok(values) = value
81        .recv_many()
82        .await
83        .map(|values| Into::<VecDeque<Value>>::into(values))
84    {
85        check!(
86            data.send_many(TransmissionValue::Other(
87                values.into_iter().map(|val| value_to_byte(val)).collect()
88            ))
89            .await
90        )
91    }
92}
93
94/// Converts any value into byte equivalent.
95fn value_to_byte(value: Value) -> Value {
96    match value {
97        Value::Void(_) => Value::Vec(Vec::new()),
98        Value::I8(val) => Value::Vec(val.to_be_bytes().iter().map(|v| Value::Byte(*v)).collect()),
99        Value::I16(val) => Value::Vec(val.to_be_bytes().iter().map(|v| Value::Byte(*v)).collect()),
100        Value::I32(val) => Value::Vec(val.to_be_bytes().iter().map(|v| Value::Byte(*v)).collect()),
101        Value::I64(val) => Value::Vec(val.to_be_bytes().iter().map(|v| Value::Byte(*v)).collect()),
102        Value::I128(val) => Value::Vec(val.to_be_bytes().iter().map(|v| Value::Byte(*v)).collect()),
103        Value::U8(val) => Value::Vec(val.to_be_bytes().iter().map(|v| Value::Byte(*v)).collect()),
104        Value::U16(val) => Value::Vec(val.to_be_bytes().iter().map(|v| Value::Byte(*v)).collect()),
105        Value::U32(val) => Value::Vec(val.to_be_bytes().iter().map(|v| Value::Byte(*v)).collect()),
106        Value::U64(val) => Value::Vec(val.to_be_bytes().iter().map(|v| Value::Byte(*v)).collect()),
107        Value::U128(val) => Value::Vec(val.to_be_bytes().iter().map(|v| Value::Byte(*v)).collect()),
108        Value::F32(val) => Value::Vec(val.to_be_bytes().iter().map(|v| Value::Byte(*v)).collect()),
109        Value::F64(val) => Value::Vec(val.to_be_bytes().iter().map(|v| Value::Byte(*v)).collect()),
110        Value::Bool(val) => Value::Vec(match val {
111            true => vec![Value::Byte(1)],
112            false => vec![Value::Byte(0)],
113        }),
114        Value::Byte(val) => Value::Vec(val.to_be_bytes().iter().map(|v| Value::Byte(*v)).collect()),
115        Value::Char(val) => Value::Vec(
116            val.to_string()
117                .as_bytes()
118                .iter()
119                .map(|v| Value::Byte(*v))
120                .collect(),
121        ),
122        Value::String(val) => Value::Vec(val.as_bytes().iter().map(|v| Value::Byte(*v)).collect()),
123        Value::Vec(vals) => Value::Vec(vals.into_iter().map(|val| value_to_byte(val)).collect()),
124        Value::Option(val) => match val {
125            Some(val) => value_to_byte(*val),
126            None => Value::Vec(Vec::new()),
127        },
128        Value::Data(_) => Value::Vec(Vec::new()),
129    }
130}
131
132/// Turns data into `i8`.
133#[mel_function(
134    generic T (ToI8)
135)]
136pub fn to_i8(value: T) -> i8 {
137    value.to_i8()
138}
139
140/// Turns stream into `i8` one.
141///
142/// This treatment manages infaillible conversions to `i8` data type.
143#[mel_treatment(
144    generic T (ToI8)
145    input value Stream<T>
146    output into Stream<i8>
147)]
148pub async fn to_i8() {
149    while let Ok(values) = value
150        .recv_many()
151        .await
152        .map(|values| Into::<VecDeque<Value>>::into(values))
153    {
154        check!(
155            into.send_many(TransmissionValue::I8(
156                values.into_iter().map(|val| val.to_i8()).collect()
157            ))
158            .await
159        )
160    }
161}
162
163/// Turns data into `i16`.
164#[mel_function(
165    generic T (ToI16)
166)]
167pub fn to_i16(value: T) -> i16 {
168    value.to_i16()
169}
170
171/// Turns stream into `i16` one.
172///
173/// This treatment manages infaillible conversions to `i16` data type.
174#[mel_treatment(
175    generic T (ToI16)
176    input value Stream<T>
177    output into Stream<i16>
178)]
179pub async fn to_i16() {
180    while let Ok(values) = value
181        .recv_many()
182        .await
183        .map(|values| Into::<VecDeque<Value>>::into(values))
184    {
185        check!(
186            into.send_many(TransmissionValue::I16(
187                values.into_iter().map(|val| val.to_i16()).collect()
188            ))
189            .await
190        )
191    }
192}
193
194/// Turns data into `i32`.
195#[mel_function(
196    generic T (ToI32)
197)]
198pub fn to_i32(value: T) -> i32 {
199    value.to_i32()
200}
201
202/// Turns stream into `i32` one.
203///
204/// This treatment manages infaillible conversions to `i32` data type.
205#[mel_treatment(
206    generic T (ToI32)
207    input value Stream<T>
208    output into Stream<i32>
209)]
210pub async fn to_i32() {
211    while let Ok(values) = value
212        .recv_many()
213        .await
214        .map(|values| Into::<VecDeque<Value>>::into(values))
215    {
216        check!(
217            into.send_many(TransmissionValue::I32(
218                values.into_iter().map(|val| val.to_i32()).collect()
219            ))
220            .await
221        )
222    }
223}
224
225/// Turns data into `i64`.
226#[mel_function(
227    generic T (ToI64)
228)]
229pub fn to_i64(value: T) -> i64 {
230    value.to_i64()
231}
232
233/// Turns stream into `i64` one.
234///
235/// This treatment manages infaillible conversions to `i64` data type.
236#[mel_treatment(
237    generic T (ToI64)
238    input value Stream<T>
239    output into Stream<i64>
240)]
241pub async fn to_i64() {
242    while let Ok(values) = value
243        .recv_many()
244        .await
245        .map(|values| Into::<VecDeque<Value>>::into(values))
246    {
247        check!(
248            into.send_many(TransmissionValue::I64(
249                values.into_iter().map(|val| val.to_i64()).collect()
250            ))
251            .await
252        )
253    }
254}
255
256/// Turns data into `i128`.
257#[mel_function(
258    generic T (ToI128)
259)]
260pub fn to_i128(value: T) -> i128 {
261    value.to_i128()
262}
263
264/// Turns stream into `i128` one.
265///
266/// This treatment manages infaillible conversions to `i128` data type.
267#[mel_treatment(
268    generic T (ToI128)
269    input value Stream<T>
270    output into Stream<i128>
271)]
272pub async fn to_i128() {
273    while let Ok(values) = value
274        .recv_many()
275        .await
276        .map(|values| Into::<VecDeque<Value>>::into(values))
277    {
278        check!(
279            into.send_many(TransmissionValue::I128(
280                values.into_iter().map(|val| val.to_i128()).collect()
281            ))
282            .await
283        )
284    }
285}
286
287/// Turns data into `u8`.
288#[mel_function(
289    generic T (ToU8)
290)]
291pub fn to_u8(value: T) -> u8 {
292    value.to_u8()
293}
294
295/// Turns stream into `u8` one.
296///
297/// This treatment manages infaillible conversions to `u8` data type.
298#[mel_treatment(
299    generic T (ToU8)
300    input value Stream<T>
301    output into Stream<u8>
302)]
303pub async fn to_u8() {
304    while let Ok(values) = value
305        .recv_many()
306        .await
307        .map(|values| Into::<VecDeque<Value>>::into(values))
308    {
309        check!(
310            into.send_many(TransmissionValue::U8(
311                values.into_iter().map(|val| val.to_u8()).collect()
312            ))
313            .await
314        )
315    }
316}
317
318/// Turns data into `u16`.
319#[mel_function(
320    generic T (ToU16)
321)]
322pub fn to_u16(value: T) -> u16 {
323    value.to_u16()
324}
325
326/// Turns stream into `u16` one.
327///
328/// This treatment manages infaillible conversions to `u16` data type.
329#[mel_treatment(
330    generic T (ToU16)
331    input value Stream<T>
332    output into Stream<u16>
333)]
334pub async fn to_u16() {
335    while let Ok(values) = value
336        .recv_many()
337        .await
338        .map(|values| Into::<VecDeque<Value>>::into(values))
339    {
340        check!(
341            into.send_many(TransmissionValue::U16(
342                values.into_iter().map(|val| val.to_u16()).collect()
343            ))
344            .await
345        )
346    }
347}
348
349/// Turns data into `u32`.
350#[mel_function(
351    generic T (ToU32)
352)]
353pub fn to_u32(value: T) -> u32 {
354    value.to_u32()
355}
356
357/// Turns stream into `u32` one.
358///
359/// This treatment manages infaillible conversions to `u32` data type.
360#[mel_treatment(
361    generic T (ToU32)
362    input value Stream<T>
363    output into Stream<u32>
364)]
365pub async fn to_u32() {
366    while let Ok(values) = value
367        .recv_many()
368        .await
369        .map(|values| Into::<VecDeque<Value>>::into(values))
370    {
371        check!(
372            into.send_many(TransmissionValue::U32(
373                values.into_iter().map(|val| val.to_u32()).collect()
374            ))
375            .await
376        )
377    }
378}
379
380/// Turns data into `u64`.
381#[mel_function(
382    generic T (ToU64)
383)]
384pub fn to_u64(value: T) -> u64 {
385    value.to_u64()
386}
387
388/// Turns stream into `u64` one.
389///
390/// This treatment manages infaillible conversions to `u64` data type.
391#[mel_treatment(
392    generic T (ToU64)
393    input value Stream<T>
394    output into Stream<u64>
395)]
396pub async fn to_u64() {
397    while let Ok(values) = value
398        .recv_many()
399        .await
400        .map(|values| Into::<VecDeque<Value>>::into(values))
401    {
402        check!(
403            into.send_many(TransmissionValue::U64(
404                values.into_iter().map(|val| val.to_u64()).collect()
405            ))
406            .await
407        )
408    }
409}
410
411/// Turns data into `u128`.
412#[mel_function(
413    generic T (ToU128)
414)]
415pub fn to_u128(value: T) -> u128 {
416    value.to_u128()
417}
418
419/// Turns stream into `u128` one.
420///
421/// This treatment manages infaillible conversions to `u128` data type.
422#[mel_treatment(
423    generic T (ToU128)
424    input value Stream<T>
425    output into Stream<u128>
426)]
427pub async fn to_u128() {
428    while let Ok(values) = value
429        .recv_many()
430        .await
431        .map(|values| Into::<VecDeque<Value>>::into(values))
432    {
433        check!(
434            into.send_many(TransmissionValue::U128(
435                values.into_iter().map(|val| val.to_u128()).collect()
436            ))
437            .await
438        )
439    }
440}
441
442/// Turns data into `f32`.
443#[mel_function(
444    generic T (ToF32)
445)]
446pub fn to_f32(value: T) -> f32 {
447    value.to_f32()
448}
449
450/// Turns stream into `f32` one.
451///
452/// This treatment manages infaillible conversions to `f32` data type.
453#[mel_treatment(
454    generic T (ToF32)
455    input value Stream<T>
456    output into Stream<f32>
457)]
458pub async fn to_f32() {
459    while let Ok(values) = value
460        .recv_many()
461        .await
462        .map(|values| Into::<VecDeque<Value>>::into(values))
463    {
464        check!(
465            into.send_many(TransmissionValue::F32(
466                values.into_iter().map(|val| val.to_f32()).collect()
467            ))
468            .await
469        )
470    }
471}
472
473/// Turns data into `f64`.
474#[mel_function(
475    generic T (ToF64)
476)]
477pub fn to_f64(value: T) -> f64 {
478    value.to_f64()
479}
480
481/// Turns stream into `f64` one.
482///
483/// This treatment manages infaillible conversions to `f64` data type.
484#[mel_treatment(
485    generic T (ToF64)
486    input value Stream<T>
487    output into Stream<f64>
488)]
489pub async fn to_f64() {
490    while let Ok(values) = value
491        .recv_many()
492        .await
493        .map(|values| Into::<VecDeque<Value>>::into(values))
494    {
495        check!(
496            into.send_many(TransmissionValue::F64(
497                values.into_iter().map(|val| val.to_f64()).collect()
498            ))
499            .await
500        )
501    }
502}
503
504/// Turns data into `bool`.
505#[mel_function(
506    generic T (ToBool)
507)]
508pub fn to_bool(value: T) -> bool {
509    value.to_bool()
510}
511
512/// Turns stream into `bool` one.
513///
514/// This treatment manages infaillible conversions to `bool` data type.
515#[mel_treatment(
516    generic T (ToBool)
517    input value Stream<T>
518    output into Stream<bool>
519)]
520pub async fn to_bool() {
521    while let Ok(values) = value
522        .recv_many()
523        .await
524        .map(|values| Into::<VecDeque<Value>>::into(values))
525    {
526        check!(
527            into.send_many(TransmissionValue::Bool(
528                values.into_iter().map(|val| val.to_bool()).collect()
529            ))
530            .await
531        )
532    }
533}
534
535/// Turns data into `byte`.
536#[mel_function(
537    generic T (ToByte)
538)]
539pub fn to_byte(value: T) -> byte {
540    value.to_byte()
541}
542
543/// Turns stream into `byte` one.
544///
545/// This treatment manages infaillible conversions to `byte` data type.
546#[mel_treatment(
547    generic T (ToByte)
548    input value Stream<T>
549    output into Stream<byte>
550)]
551pub async fn to_byte() {
552    while let Ok(values) = value
553        .recv_many()
554        .await
555        .map(|values| Into::<VecDeque<Value>>::into(values))
556    {
557        check!(
558            into.send_many(TransmissionValue::Byte(
559                values.into_iter().map(|val| val.to_byte()).collect()
560            ))
561            .await
562        )
563    }
564}
565
566/// Turns data into `char`.
567#[mel_function(
568    generic T (ToChar)
569)]
570pub fn to_char(value: T) -> char {
571    value.to_char()
572}
573
574/// Turns stream into `char` one.
575///
576/// This treatment manages infaillible conversions to `char` data type.
577#[mel_treatment(
578    generic T (ToChar)
579    input value Stream<T>
580    output into Stream<char>
581)]
582pub async fn to_char() {
583    while let Ok(values) = value
584        .recv_many()
585        .await
586        .map(|values| Into::<VecDeque<Value>>::into(values))
587    {
588        check!(
589            into.send_many(TransmissionValue::Char(
590                values.into_iter().map(|val| val.to_char()).collect()
591            ))
592            .await
593        )
594    }
595}
596
597/// Turns data into `string`.
598#[mel_function(
599    generic T (ToString)
600)]
601pub fn to_string(value: T) -> string {
602    DataTrait::to_string(&value)
603}
604
605/// Turns stream into `string` one.
606///
607/// This treatment manages infaillible conversions to `string` data type.
608#[mel_treatment(
609    generic T (ToString)
610    input value Stream<T>
611    output into Stream<string>
612)]
613pub async fn to_string() {
614    while let Ok(values) = value
615        .recv_many()
616        .await
617        .map(|values| Into::<VecDeque<Value>>::into(values))
618    {
619        check!(
620            into.send_many(TransmissionValue::String(
621                values
622                    .into_iter()
623                    .map(|val| DataTrait::to_string(&val))
624                    .collect()
625            ))
626            .await
627        )
628    }
629}
630
631/// Try to turn data into `i8`.
632///
633/// This function returns an `Option` containing value if conversion is successful.
634#[mel_function(
635    generic T (TryToI8)
636)]
637pub fn try_to_i8(value: T) -> Option<i8> {
638    value.try_to_i8()
639}
640
641/// Try to turn data stream into `i8` one.
642///
643/// This treatment manages faillible conversion to `i8` data type.
644/// If conversion is successful, an option with `i8` value is streamed, else the option is set to none.
645#[mel_treatment(
646    generic T (TryToI8)
647    input value Stream<T>
648    output into Stream<Option<i8>>
649)]
650pub async fn try_to_i8() {
651    while let Ok(values) = value
652        .recv_many()
653        .await
654        .map(|values| Into::<VecDeque<Value>>::into(values))
655    {
656        check!(
657            into.send_many(TransmissionValue::Other(
658                values
659                    .into_iter()
660                    .map(|val| val.try_to_i8().into())
661                    .collect()
662            ))
663            .await
664        )
665    }
666}
667
668/// Try to turn data into `i16`.
669///
670/// This function returns an `Option` containing value if conversion is successful.
671#[mel_function(
672    generic T (TryToI16)
673)]
674pub fn try_to_i16(value: T) -> Option<i16> {
675    value.try_to_i16()
676}
677
678/// Try to turn data stream into `i16` one.
679///
680/// This treatment manages faillible conversion to `i16` data type.
681/// If conversion is successful, an option with `i16` value is streamed, else the option is set to none.
682#[mel_treatment(
683    generic T (TryToI16)
684    input value Stream<T>
685    output into Stream<Option<i16>>
686)]
687pub async fn try_to_i16() {
688    while let Ok(values) = value
689        .recv_many()
690        .await
691        .map(|values| Into::<VecDeque<Value>>::into(values))
692    {
693        check!(
694            into.send_many(TransmissionValue::Other(
695                values
696                    .into_iter()
697                    .map(|val| val.try_to_i16().into())
698                    .collect()
699            ))
700            .await
701        )
702    }
703}
704
705/// Try to turn data into `i32`.
706///
707/// This function returns an `Option` containing value if conversion is successful.
708#[mel_function(
709    generic T (TryToI32)
710)]
711pub fn try_to_i32(value: T) -> Option<i32> {
712    value.try_to_i32()
713}
714
715/// Try to turn data stream into `i32` one.
716///
717/// This treatment manages faillible conversion to `i32` data type.
718/// If conversion is successful, an option with `i32` value is streamed, else the option is set to none.
719#[mel_treatment(
720    generic T (TryToI32)
721    input value Stream<T>
722    output into Stream<Option<i32>>
723)]
724pub async fn try_to_i32() {
725    while let Ok(values) = value
726        .recv_many()
727        .await
728        .map(|values| Into::<VecDeque<Value>>::into(values))
729    {
730        check!(
731            into.send_many(TransmissionValue::Other(
732                values
733                    .into_iter()
734                    .map(|val| val.try_to_i32().into())
735                    .collect()
736            ))
737            .await
738        )
739    }
740}
741
742/// Try to turn data into `i64`.
743///
744/// This function returns an `Option` containing value if conversion is successful.
745#[mel_function(
746    generic T (TryToI64)
747)]
748pub fn try_to_i64(value: T) -> Option<i64> {
749    value.try_to_i64()
750}
751
752/// Try to turn data stream into `i64` one.
753///
754/// This treatment manages faillible conversion to `i64` data type.
755/// If conversion is successful, an option with `i64` value is streamed, else the option is set to none.
756#[mel_treatment(
757    generic T (TryToI64)
758    input value Stream<T>
759    output into Stream<Option<i64>>
760)]
761pub async fn try_to_i64() {
762    while let Ok(values) = value
763        .recv_many()
764        .await
765        .map(|values| Into::<VecDeque<Value>>::into(values))
766    {
767        check!(
768            into.send_many(TransmissionValue::Other(
769                values
770                    .into_iter()
771                    .map(|val| val.try_to_i64().into())
772                    .collect()
773            ))
774            .await
775        )
776    }
777}
778
779/// Try to turn data into `i128`.
780///
781/// This function returns an `Option` containing value if conversion is successful.
782#[mel_function(
783    generic T (TryToI128)
784)]
785pub fn try_to_i128(value: T) -> Option<i128> {
786    value.try_to_i128()
787}
788
789/// Try to turn data stream into `i128` one.
790///
791/// This treatment manages faillible conversion to `i128` data type.
792/// If conversion is successful, an option with `i128` value is streamed, else the option is set to none.
793#[mel_treatment(
794    generic T (TryToI128)
795    input value Stream<T>
796    output into Stream<Option<i128>>
797)]
798pub async fn try_to_i128() {
799    while let Ok(values) = value
800        .recv_many()
801        .await
802        .map(|values| Into::<VecDeque<Value>>::into(values))
803    {
804        check!(
805            into.send_many(TransmissionValue::Other(
806                values
807                    .into_iter()
808                    .map(|val| val.try_to_i128().into())
809                    .collect()
810            ))
811            .await
812        )
813    }
814}
815
816/// Try to turn data into `u8`.
817///
818/// This function returns an `Option` containing value if conversion is successful.
819#[mel_function(
820    generic T (TryToU8)
821)]
822pub fn try_to_u8(value: T) -> Option<u8> {
823    value.try_to_u8()
824}
825
826/// Try to turn data stream into `u8` one.
827///
828/// This treatment manages faillible conversion to `u8` data type.
829/// If conversion is successful, an option with `u8` value is streamed, else the option is set to none.
830#[mel_treatment(
831    generic T (TryToU8)
832    input value Stream<T>
833    output into Stream<Option<u8>>
834)]
835pub async fn try_to_u8() {
836    while let Ok(values) = value
837        .recv_many()
838        .await
839        .map(|values| Into::<VecDeque<Value>>::into(values))
840    {
841        check!(
842            into.send_many(TransmissionValue::Other(
843                values
844                    .into_iter()
845                    .map(|val| val.try_to_u8().into())
846                    .collect()
847            ))
848            .await
849        )
850    }
851}
852
853/// Try to turn data into `u16`.
854///
855/// This function returns an `Option` containing value if conversion is successful.
856#[mel_function(
857    generic T (TryToU16)
858)]
859pub fn try_to_u16(value: T) -> Option<u16> {
860    value.try_to_u16()
861}
862
863/// Try to turn data stream into `u16` one.
864///
865/// This treatment manages faillible conversion to `u16` data type.
866/// If conversion is successful, an option with `u16` value is streamed, else the option is set to none.
867#[mel_treatment(
868    generic T (TryToU16)
869    input value Stream<T>
870    output into Stream<Option<u16>>
871)]
872pub async fn try_to_u16() {
873    while let Ok(values) = value
874        .recv_many()
875        .await
876        .map(|values| Into::<VecDeque<Value>>::into(values))
877    {
878        check!(
879            into.send_many(TransmissionValue::Other(
880                values
881                    .into_iter()
882                    .map(|val| val.try_to_u16().into())
883                    .collect()
884            ))
885            .await
886        )
887    }
888}
889
890/// Try to turn data into `u32`.
891///
892/// This function returns an `Option` containing value if conversion is successful.
893#[mel_function(
894    generic T (TryToU32)
895)]
896pub fn try_to_u32(value: T) -> Option<u32> {
897    value.try_to_u32()
898}
899
900/// Try to turn data stream into `u32` one.
901///
902/// This treatment manages faillible conversion to `u32` data type.
903/// If conversion is successful, an option with `u32` value is streamed, else the option is set to none.
904#[mel_treatment(
905    generic T (TryToU32)
906    input value Stream<T>
907    output into Stream<Option<u32>>
908)]
909pub async fn try_to_u32() {
910    while let Ok(values) = value
911        .recv_many()
912        .await
913        .map(|values| Into::<VecDeque<Value>>::into(values))
914    {
915        check!(
916            into.send_many(TransmissionValue::Other(
917                values
918                    .into_iter()
919                    .map(|val| val.try_to_u32().into())
920                    .collect()
921            ))
922            .await
923        )
924    }
925}
926
927/// Try to turn data into `u64`.
928///
929/// This function returns an `Option` containing value if conversion is successful.
930#[mel_function(
931    generic T (TryToU64)
932)]
933pub fn try_to_u64(value: T) -> Option<u64> {
934    value.try_to_u64()
935}
936
937/// Try to turn data stream into `u64` one.
938///
939/// This treatment manages faillible conversion to `u64` data type.
940/// If conversion is successful, an option with `u64` value is streamed, else the option is set to none.
941#[mel_treatment(
942    generic T (TryToU64)
943    input value Stream<T>
944    output into Stream<Option<u64>>
945)]
946pub async fn try_to_u64() {
947    while let Ok(values) = value
948        .recv_many()
949        .await
950        .map(|values| Into::<VecDeque<Value>>::into(values))
951    {
952        check!(
953            into.send_many(TransmissionValue::Other(
954                values
955                    .into_iter()
956                    .map(|val| val.try_to_u64().into())
957                    .collect()
958            ))
959            .await
960        )
961    }
962}
963
964/// Try to turn data into `u128`.
965///
966/// This function returns an `Option` containing value if conversion is successful.
967#[mel_function(
968    generic T (TryToU128)
969)]
970pub fn try_to_u128(value: T) -> Option<u128> {
971    value.try_to_u128()
972}
973
974/// Try to turn data stream into `u128` one.
975///
976/// This treatment manages faillible conversion to `u128` data type.
977/// If conversion is successful, an option with `u128` value is streamed, else the option is set to none.
978#[mel_treatment(
979    generic T (TryToU128)
980    input value Stream<T>
981    output into Stream<Option<u128>>
982)]
983pub async fn try_to_u128() {
984    while let Ok(values) = value
985        .recv_many()
986        .await
987        .map(|values| Into::<VecDeque<Value>>::into(values))
988    {
989        check!(
990            into.send_many(TransmissionValue::Other(
991                values
992                    .into_iter()
993                    .map(|val| val.try_to_u128().into())
994                    .collect()
995            ))
996            .await
997        )
998    }
999}
1000
1001/// Try to turn data into `f32`.
1002///
1003/// This function returns an `Option` containing value if conversion is successful.
1004#[mel_function(
1005    generic T (TryToF32)
1006)]
1007pub fn try_to_f32(value: T) -> Option<f32> {
1008    value.try_to_f32()
1009}
1010
1011/// Try to turn data stream into `f32` one.
1012///
1013/// This treatment manages faillible conversion to `f32` data type.
1014/// If conversion is successful, an option with `f32` value is streamed, else the option is set to none.
1015#[mel_treatment(
1016    generic T (TryToF32)
1017    input value Stream<T>
1018    output into Stream<Option<f32>>
1019)]
1020pub async fn try_to_f32() {
1021    while let Ok(values) = value
1022        .recv_many()
1023        .await
1024        .map(|values| Into::<VecDeque<Value>>::into(values))
1025    {
1026        check!(
1027            into.send_many(TransmissionValue::Other(
1028                values
1029                    .into_iter()
1030                    .map(|val| val.try_to_f32().into())
1031                    .collect()
1032            ))
1033            .await
1034        )
1035    }
1036}
1037
1038/// Try to turn data into `f64`.
1039///
1040/// This function returns an `Option` containing value if conversion is successful.
1041#[mel_function(
1042    generic T (TryToF64)
1043)]
1044pub fn try_to_f64(value: T) -> Option<f64> {
1045    value.try_to_f64()
1046}
1047
1048/// Try to turn data stream into `f64` one.
1049///
1050/// This treatment manages faillible conversion to `f64` data type.
1051/// If conversion is successful, an option with `f64` value is streamed, else the option is set to none.
1052#[mel_treatment(
1053    generic T (TryToF64)
1054    input value Stream<T>
1055    output into Stream<Option<f64>>
1056)]
1057pub async fn try_to_f64() {
1058    while let Ok(values) = value
1059        .recv_many()
1060        .await
1061        .map(|values| Into::<VecDeque<Value>>::into(values))
1062    {
1063        check!(
1064            into.send_many(TransmissionValue::Other(
1065                values
1066                    .into_iter()
1067                    .map(|val| val.try_to_f64().into())
1068                    .collect()
1069            ))
1070            .await
1071        )
1072    }
1073}
1074
1075/// Try to turn data into `bool`.
1076///
1077/// This function returns an `Option` containing value if conversion is successful.
1078#[mel_function(
1079    generic T (TryToBool)
1080)]
1081pub fn try_to_bool(value: T) -> Option<bool> {
1082    value.try_to_bool()
1083}
1084
1085/// Try to turn data stream into `bool` one.
1086///
1087/// This treatment manages faillible conversion to `bool` data type.
1088/// If conversion is successful, an option with `bool` value is streamed, else the option is set to none.
1089#[mel_treatment(
1090    generic T (TryToBool)
1091    input value Stream<T>
1092    output into Stream<Option<bool>>
1093)]
1094pub async fn try_to_bool() {
1095    while let Ok(values) = value
1096        .recv_many()
1097        .await
1098        .map(|values| Into::<VecDeque<Value>>::into(values))
1099    {
1100        check!(
1101            into.send_many(TransmissionValue::Other(
1102                values
1103                    .into_iter()
1104                    .map(|val| val.try_to_bool().into())
1105                    .collect()
1106            ))
1107            .await
1108        )
1109    }
1110}
1111
1112/// Try to turn data into `byte`.
1113///
1114/// This function returns an `Option` containing value if conversion is successful.
1115#[mel_function(
1116    generic T (TryToByte)
1117)]
1118pub fn try_to_byte(value: T) -> Option<byte> {
1119    value.try_to_byte()
1120}
1121
1122/// Try to turn data stream into `byte` one.
1123///
1124/// This treatment manages faillible conversion to `byte` data type.
1125/// If conversion is successful, an option with `byte` value is streamed, else the option is set to none.
1126#[mel_treatment(
1127    generic T (TryToByte)
1128    input value Stream<T>
1129    output into Stream<Option<byte>>
1130)]
1131pub async fn try_to_byte() {
1132    while let Ok(values) = value
1133        .recv_many()
1134        .await
1135        .map(|values| Into::<VecDeque<Value>>::into(values))
1136    {
1137        check!(
1138            into.send_many(TransmissionValue::Other(
1139                values
1140                    .into_iter()
1141                    .map(|val| val.try_to_byte().into())
1142                    .collect()
1143            ))
1144            .await
1145        )
1146    }
1147}
1148
1149/// Try to turn data into `char`.
1150///
1151/// This function returns an `Option` containing value if conversion is successful.
1152#[mel_function(
1153    generic T (TryToChar)
1154)]
1155pub fn try_to_char(value: T) -> Option<char> {
1156    value.try_to_char()
1157}
1158
1159/// Try to turn data stream into `char` one.
1160///
1161/// This treatment manages faillible conversion to `char` data type.
1162/// If conversion is successful, an option with `char` value is streamed, else the option is set to none.
1163#[mel_treatment(
1164    generic T (TryToChar)
1165    input value Stream<T>
1166    output into Stream<Option<char>>
1167)]
1168pub async fn try_to_char() {
1169    while let Ok(values) = value
1170        .recv_many()
1171        .await
1172        .map(|values| Into::<VecDeque<Value>>::into(values))
1173    {
1174        check!(
1175            into.send_many(TransmissionValue::Other(
1176                values
1177                    .into_iter()
1178                    .map(|val| val.try_to_char().into())
1179                    .collect()
1180            ))
1181            .await
1182        )
1183    }
1184}
1185
1186/// Try to turn data into `string`.
1187///
1188/// This function returns an `Option` containing value if conversion is successful.
1189#[mel_function(
1190    generic T (TryToString)
1191)]
1192pub fn try_to_string(value: T) -> Option<string> {
1193    value.try_to_string()
1194}
1195
1196/// Try to turn data stream into `string` one.
1197///
1198/// This treatment manages faillible conversion to `string` data type.
1199/// If conversion is successful, an option with `string` value is streamed, else the option is set to none.
1200#[mel_treatment(
1201    generic T (TryToString)
1202    input value Stream<T>
1203    output into Stream<Option<string>>
1204)]
1205pub async fn try_to_string() {
1206    while let Ok(values) = value
1207        .recv_many()
1208        .await
1209        .map(|values| Into::<VecDeque<Value>>::into(values))
1210    {
1211        check!(
1212            into.send_many(TransmissionValue::Other(
1213                values
1214                    .into_iter()
1215                    .map(|val| val.try_to_string().into())
1216                    .collect()
1217            ))
1218            .await
1219        )
1220    }
1221}
1222
1223/// Turns data into `i8`, saturating if needed.
1224///
1225/// This function makes a saturating and infaillible conversion to `i8`.
1226/// If incoming data represents something out of bounds for `i8`, then
1227/// the resulting value is set to minimum or maximum, depending what is
1228/// the closest to truth.
1229#[mel_function(
1230    generic T (SaturatingToI8)
1231)]
1232pub fn saturating_to_i8(value: T) -> i8 {
1233    value.saturating_to_i8()
1234}
1235
1236/// Turns stream into `i8` one, saturating if needed.
1237///
1238/// This treatment manages saturating and infaillible conversion to `i8`.
1239/// If incoming data represents something out of bounds for `i8`, then
1240/// the resulting value is set to minimum or maximum, depending what is
1241/// the closest to truth.
1242#[mel_treatment(
1243    generic T (SaturatingToI8)
1244    input value Stream<T>
1245    output into Stream<i8>
1246)]
1247pub async fn saturating_to_i8() {
1248    while let Ok(values) = value
1249        .recv_many()
1250        .await
1251        .map(|values| Into::<VecDeque<Value>>::into(values))
1252    {
1253        check!(
1254            into.send_many(TransmissionValue::I8(
1255                values
1256                    .into_iter()
1257                    .map(|val| val.saturating_to_i8())
1258                    .collect()
1259            ))
1260            .await
1261        )
1262    }
1263}
1264
1265/// Turns data into `i16`, saturating if needed.
1266///
1267/// This function makes a saturating and infaillible conversion to `i16`.
1268/// If incoming data represents something out of bounds for `i16`, then
1269/// the resulting value is set to minimum or maximum, depending what is
1270/// the closest to truth.
1271#[mel_function(
1272    generic T (SaturatingToI16)
1273)]
1274pub fn saturating_to_i16(value: T) -> i16 {
1275    value.saturating_to_i16()
1276}
1277
1278/// Turns stream into `i16` one, saturating if needed.
1279///
1280/// This treatment manages saturating and infaillible conversion to `i16`.
1281/// If incoming data represents something out of bounds for `i16`, then
1282/// the resulting value is set to minimum or maximum, depending what is
1283/// the closest to truth.
1284#[mel_treatment(
1285    generic T (SaturatingToI16)
1286    input value Stream<T>
1287    output into Stream<i16>
1288)]
1289pub async fn saturating_to_i16() {
1290    while let Ok(values) = value
1291        .recv_many()
1292        .await
1293        .map(|values| Into::<VecDeque<Value>>::into(values))
1294    {
1295        check!(
1296            into.send_many(TransmissionValue::I16(
1297                values
1298                    .into_iter()
1299                    .map(|val| val.saturating_to_i16())
1300                    .collect()
1301            ))
1302            .await
1303        )
1304    }
1305}
1306
1307/// Turns data into `i32`, saturating if needed.
1308///
1309/// This function makes a saturating and infaillible conversion to `i32`.
1310/// If incoming data represents something out of bounds for `i32`, then
1311/// the resulting value is set to minimum or maximum, depending what is
1312/// the closest to truth.
1313#[mel_function(
1314    generic T (SaturatingToI32)
1315)]
1316pub fn saturating_to_i32(value: T) -> i32 {
1317    value.saturating_to_i32()
1318}
1319
1320/// Turns stream into `i32` one, saturating if needed.
1321///
1322/// This treatment manages saturating and infaillible conversion to `i32`.
1323/// If incoming data represents something out of bounds for `i32`, then
1324/// the resulting value is set to minimum or maximum, depending what is
1325/// the closest to truth.
1326#[mel_treatment(
1327    generic T (SaturatingToI32)
1328    input value Stream<T>
1329    output into Stream<i32>
1330)]
1331pub async fn saturating_to_i32() {
1332    while let Ok(values) = value
1333        .recv_many()
1334        .await
1335        .map(|values| Into::<VecDeque<Value>>::into(values))
1336    {
1337        check!(
1338            into.send_many(TransmissionValue::I32(
1339                values
1340                    .into_iter()
1341                    .map(|val| val.saturating_to_i32())
1342                    .collect()
1343            ))
1344            .await
1345        )
1346    }
1347}
1348
1349/// Turns data into `i64`, saturating if needed.
1350///
1351/// This function makes a saturating and infaillible conversion to `i64`.
1352/// If incoming data represents something out of bounds for `i64`, then
1353/// the resulting value is set to minimum or maximum, depending what is
1354/// the closest to truth.
1355#[mel_function(
1356    generic T (SaturatingToI64)
1357)]
1358pub fn saturating_to_i64(value: T) -> i64 {
1359    value.saturating_to_i64()
1360}
1361
1362/// Turns stream into `i64` one, saturating if needed.
1363///
1364/// This treatment manages saturating and infaillible conversion to `i64`.
1365/// If incoming data represents something out of bounds for `i64`, then
1366/// the resulting value is set to minimum or maximum, depending what is
1367/// the closest to truth.
1368#[mel_treatment(
1369    generic T (SaturatingToI64)
1370    input value Stream<T>
1371    output into Stream<i64>
1372)]
1373pub async fn saturating_to_i64() {
1374    while let Ok(values) = value
1375        .recv_many()
1376        .await
1377        .map(|values| Into::<VecDeque<Value>>::into(values))
1378    {
1379        check!(
1380            into.send_many(TransmissionValue::I64(
1381                values
1382                    .into_iter()
1383                    .map(|val| val.saturating_to_i64())
1384                    .collect()
1385            ))
1386            .await
1387        )
1388    }
1389}
1390
1391/// Turns data into `i128`, saturating if needed.
1392///
1393/// This function makes a saturating and infaillible conversion to `i128`.
1394/// If incoming data represents something out of bounds for `i128`, then
1395/// the resulting value is set to minimum or maximum, depending what is
1396/// the closest to truth.
1397#[mel_function(
1398    generic T (SaturatingToI128)
1399)]
1400pub fn saturating_to_i128(value: T) -> i128 {
1401    value.saturating_to_i128()
1402}
1403
1404/// Turns stream into `i128` one, saturating if needed.
1405///
1406/// This treatment manages saturating and infaillible conversion to `i128`.
1407/// If incoming data represents something out of bounds for `i128`, then
1408/// the resulting value is set to minimum or maximum, depending what is
1409/// the closest to truth.
1410#[mel_treatment(
1411    generic T (SaturatingToI128)
1412    input value Stream<T>
1413    output into Stream<i128>
1414)]
1415pub async fn saturating_to_i128() {
1416    while let Ok(values) = value
1417        .recv_many()
1418        .await
1419        .map(|values| Into::<VecDeque<Value>>::into(values))
1420    {
1421        check!(
1422            into.send_many(TransmissionValue::I128(
1423                values
1424                    .into_iter()
1425                    .map(|val| val.saturating_to_i128())
1426                    .collect()
1427            ))
1428            .await
1429        )
1430    }
1431}
1432
1433/// Turns data into `u8`, saturating if needed.
1434///
1435/// This function makes a saturating and infaillible conversion to `u8`.
1436/// If incoming data represents something out of bounds for `u8`, then
1437/// the resulting value is set to minimum or maximum, depending what is
1438/// the closest to truth.
1439#[mel_function(
1440    generic T (SaturatingToU8)
1441)]
1442pub fn saturating_to_u8(value: T) -> u8 {
1443    value.saturating_to_u8()
1444}
1445
1446/// Turns stream into `u8` one, saturating if needed.
1447///
1448/// This treatment manages saturating and infaillible conversion to `u8`.
1449/// If incoming data represents something out of bounds for `u8`, then
1450/// the resulting value is set to minimum or maximum, depending what is
1451/// the closest to truth.
1452#[mel_treatment(
1453    generic T (SaturatingToU8)
1454    input value Stream<T>
1455    output into Stream<u8>
1456)]
1457pub async fn saturating_to_u8() {
1458    while let Ok(values) = value
1459        .recv_many()
1460        .await
1461        .map(|values| Into::<VecDeque<Value>>::into(values))
1462    {
1463        check!(
1464            into.send_many(TransmissionValue::U8(
1465                values
1466                    .into_iter()
1467                    .map(|val| val.saturating_to_u8())
1468                    .collect()
1469            ))
1470            .await
1471        )
1472    }
1473}
1474
1475/// Turns data into `u16`, saturating if needed.
1476///
1477/// This function makes a saturating and infaillible conversion to `u16`.
1478/// If incoming data represents something out of bounds for `u16`, then
1479/// the resulting value is set to minimum or maximum, depending what is
1480/// the closest to truth.
1481#[mel_function(
1482    generic T (SaturatingToU16)
1483)]
1484pub fn saturating_to_u16(value: T) -> u16 {
1485    value.saturating_to_u16()
1486}
1487
1488/// Turns stream into `u16` one, saturating if needed.
1489///
1490/// This treatment manages saturating and infaillible conversion to `u16`.
1491/// If incoming data represents something out of bounds for `u16`, then
1492/// the resulting value is set to minimum or maximum, depending what is
1493/// the closest to truth.
1494#[mel_treatment(
1495    generic T (SaturatingToU16)
1496    input value Stream<T>
1497    output into Stream<u16>
1498)]
1499pub async fn saturating_to_u16() {
1500    while let Ok(values) = value
1501        .recv_many()
1502        .await
1503        .map(|values| Into::<VecDeque<Value>>::into(values))
1504    {
1505        check!(
1506            into.send_many(TransmissionValue::U16(
1507                values
1508                    .into_iter()
1509                    .map(|val| val.saturating_to_u16())
1510                    .collect()
1511            ))
1512            .await
1513        )
1514    }
1515}
1516
1517/// Turns data into `u32`, saturating if needed.
1518///
1519/// This function makes a saturating and infaillible conversion to `u32`.
1520/// If incoming data represents something out of bounds for `u32`, then
1521/// the resulting value is set to minimum or maximum, depending what is
1522/// the closest to truth.
1523#[mel_function(
1524    generic T (SaturatingToU32)
1525)]
1526pub fn saturating_to_u32(value: T) -> u32 {
1527    value.saturating_to_u32()
1528}
1529
1530/// Turns stream into `u32` one, saturating if needed.
1531///
1532/// This treatment manages saturating and infaillible conversion to `u32`.
1533/// If incoming data represents something out of bounds for `u32`, then
1534/// the resulting value is set to minimum or maximum, depending what is
1535/// the closest to truth.
1536#[mel_treatment(
1537    generic T (SaturatingToU32)
1538    input value Stream<T>
1539    output into Stream<u32>
1540)]
1541pub async fn saturating_to_u32() {
1542    while let Ok(values) = value
1543        .recv_many()
1544        .await
1545        .map(|values| Into::<VecDeque<Value>>::into(values))
1546    {
1547        check!(
1548            into.send_many(TransmissionValue::U32(
1549                values
1550                    .into_iter()
1551                    .map(|val| val.saturating_to_u32())
1552                    .collect()
1553            ))
1554            .await
1555        )
1556    }
1557}
1558
1559/// Turns data into `u64`, saturating if needed.
1560///
1561/// This function makes a saturating and infaillible conversion to `u64`.
1562/// If incoming data represents something out of bounds for `u64`, then
1563/// the resulting value is set to minimum or maximum, depending what is
1564/// the closest to truth.
1565#[mel_function(
1566    generic T (SaturatingToU64)
1567)]
1568pub fn saturating_to_u64(value: T) -> u64 {
1569    value.saturating_to_u64()
1570}
1571
1572/// Turns stream into `u64` one, saturating if needed.
1573///
1574/// This treatment manages saturating and infaillible conversion to `u64`.
1575/// If incoming data represents something out of bounds for `u64`, then
1576/// the resulting value is set to minimum or maximum, depending what is
1577/// the closest to truth.
1578#[mel_treatment(
1579    generic T (SaturatingToU64)
1580    input value Stream<T>
1581    output into Stream<u64>
1582)]
1583pub async fn saturating_to_u64() {
1584    while let Ok(values) = value
1585        .recv_many()
1586        .await
1587        .map(|values| Into::<VecDeque<Value>>::into(values))
1588    {
1589        check!(
1590            into.send_many(TransmissionValue::U64(
1591                values
1592                    .into_iter()
1593                    .map(|val| val.saturating_to_u64())
1594                    .collect()
1595            ))
1596            .await
1597        )
1598    }
1599}
1600
1601/// Turns data into `u128`, saturating if needed.
1602///
1603/// This function makes a saturating and infaillible conversion to `u128`.
1604/// If incoming data represents something out of bounds for `u128`, then
1605/// the resulting value is set to minimum or maximum, depending what is
1606/// the closest to truth.
1607#[mel_function(
1608    generic T (SaturatingToU128)
1609)]
1610pub fn saturating_to_u128(value: T) -> u128 {
1611    value.saturating_to_u128()
1612}
1613
1614/// Turns stream into `u128` one, saturating if needed.
1615///
1616/// This treatment manages saturating and infaillible conversion to `u128`.
1617/// If incoming data represents something out of bounds for `u128`, then
1618/// the resulting value is set to minimum or maximum, depending what is
1619/// the closest to truth.
1620#[mel_treatment(
1621    generic T (SaturatingToU128)
1622    input value Stream<T>
1623    output into Stream<u128>
1624)]
1625pub async fn saturating_to_u128() {
1626    while let Ok(values) = value
1627        .recv_many()
1628        .await
1629        .map(|values| Into::<VecDeque<Value>>::into(values))
1630    {
1631        check!(
1632            into.send_many(TransmissionValue::U128(
1633                values
1634                    .into_iter()
1635                    .map(|val| val.saturating_to_u128())
1636                    .collect()
1637            ))
1638            .await
1639        )
1640    }
1641}
1642
1643/// Turns data into `f32`, saturating if needed.
1644///
1645/// This function makes a saturating and infaillible conversion to `f32`.
1646/// If incoming data represents something not representable purely in `f32`,
1647/// then the resulting value is set to the closest approximation possible.
1648#[mel_function(
1649    generic T (SaturatingToF32)
1650)]
1651pub fn saturating_to_f32(value: T) -> f32 {
1652    value.saturating_to_f32()
1653}
1654
1655/// Turns stream into `f32` one, saturating if needed.
1656///
1657/// This treatment manages saturating and infaillible conversion to `f32`.
1658/// If incoming data represents something out of bounds for `f32`,
1659/// then the resulting value is set to the closest approximation possible.
1660#[mel_treatment(
1661    generic T (SaturatingToF32)
1662    input value Stream<T>
1663    output into Stream<f32>
1664)]
1665pub async fn saturating_to_f32() {
1666    while let Ok(values) = value
1667        .recv_many()
1668        .await
1669        .map(|values| Into::<VecDeque<Value>>::into(values))
1670    {
1671        check!(
1672            into.send_many(TransmissionValue::F32(
1673                values
1674                    .into_iter()
1675                    .map(|val| val.saturating_to_f32())
1676                    .collect()
1677            ))
1678            .await
1679        )
1680    }
1681}
1682
1683/// Turns data into `f64`, saturating if needed.
1684///
1685/// This function makes a saturating and infaillible conversion to `f64`.
1686/// If incoming data represents something out of bounds for `f64`,
1687/// then the resulting value is set to the closest approximation possible.
1688#[mel_function(
1689    generic T (SaturatingToF64)
1690)]
1691pub fn saturating_to_f64(value: T) -> f64 {
1692    value.saturating_to_f64()
1693}
1694
1695/// Turns stream into `f64` one, saturating if needed.
1696///
1697/// This treatment manages saturating and infaillible conversion to `f64`.
1698/// If incoming data represents something out of bounds for `f64`,
1699/// then the resulting value is set to the closest approximation possible.
1700#[mel_treatment(
1701    generic T (SaturatingToF64)
1702    input value Stream<T>
1703    output into Stream<f64>
1704)]
1705pub async fn saturating_to_f64() {
1706    while let Ok(values) = value
1707        .recv_many()
1708        .await
1709        .map(|values| Into::<VecDeque<Value>>::into(values))
1710    {
1711        check!(
1712            into.send_many(TransmissionValue::F64(
1713                values
1714                    .into_iter()
1715                    .map(|val| val.saturating_to_f64())
1716                    .collect()
1717            ))
1718            .await
1719        )
1720    }
1721}