Skip to main content

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