fidl_next_codec/
into_natural.rs1use crate::{FromWire, WireF32, WireF64, WireI16, WireI32, WireI64, WireU16, WireU32, WireU64};
6
7pub trait IntoNatural: Sized {
9 type Natural: FromWire<Self>;
11
12 fn into_natural(self) -> Self::Natural {
14 Self::Natural::from_wire(self)
15 }
16}
17
18macro_rules! impl_primitive {
19 ($ty:ty) => {
20 impl_primitive!($ty, $ty);
21 };
22 ($wire:ty, $natural:ty) => {
23 impl IntoNatural for $wire {
24 type Natural = $natural;
25 }
26 };
27}
28
29macro_rules! impl_primitives {
30 ($($wire:ty $(, $natural:ty)?);* $(;)?) => {
31 $(
32 impl_primitive!($wire $(, $natural)?);
33 )*
34 }
35}
36
37impl_primitives! {
38 ();
39
40 bool;
41
42 i8;
43 WireI16, i16;
44 WireI32, i32;
45 WireI64, i64;
46
47 u8;
48 WireU16, u16;
49 WireU32, u32;
50 WireU64, u64;
51
52 WireF32, f32;
53 WireF64, f64;
54}
55
56impl<W: IntoNatural, const N: usize> IntoNatural for [W; N] {
57 type Natural = [W::Natural; N];
58}