userspace/traits/
bytes.rs

1pub trait Bytes<Observer, Reference> {
2    const BYTES_SIZE: usize;
3
4    fn to_bytes(&self, endianness: bool) -> [u8; Self::BYTES_SIZE];
5    fn to_le_bytes(&self) -> [u8; Self::BYTES_SIZE] {
6        self.to_bytes(true)
7    }
8    fn to_be_bytes(&self) -> [u8; Self::BYTES_SIZE] {
9        self.to_bytes(false)
10    }
11
12    fn from_bytes(bytes: [u8; Self::BYTES_SIZE], endianness: bool) -> Self;
13    fn from_le_bytes(bytes: [u8; Self::BYTES_SIZE]) -> Self
14    where
15        Self: Sized,
16    {
17        Self::from_bytes(bytes, true)
18    }
19    fn from_be_bytes(bytes: [u8; Self::BYTES_SIZE]) -> Self
20    where
21        Self: Sized,
22    {
23        Self::from_bytes(bytes, false)
24    }
25}
26
27// pub trait Bytes<Observer, Reference> {
28//     const BYTES_SIZE: usize;
29
30//     fn to_bytes(&self, endianness: bool) -> [u8; Self::BYTES_SIZE]
31//     where
32//         [u8; Self::BYTES_SIZE]:;
33//     fn to_le_bytes(&self) -> [u8; Self::BYTES_SIZE]
34//     where
35//         [u8; Self::BYTES_SIZE]:,
36//     {
37//         self.to_bytes(true)
38//     }
39//     fn to_be_bytes(&self) -> [u8; Self::BYTES_SIZE]
40//     where
41//         [u8; Self::BYTES_SIZE]:,
42//     {
43//         self.to_bytes(false)
44//     }
45//     fn from_bytes(bytes: [u8; Self::BYTES_SIZE], endianness: bool) -> Self
46//     where
47//         [u8; Self::BYTES_SIZE]:;
48//     fn from_le_bytes(bytes: [u8; Self::BYTES_SIZE]) -> Self
49//     where
50//         Self: Sized,
51//         [u8; Self::BYTES_SIZE]:,
52//     {
53//         Self::from_bytes(bytes, true)
54//     }
55//     fn from_be_bytes(bytes: [u8; Self::BYTES_SIZE]) -> Self
56//     where
57//         Self: Sized,
58//         [u8; Self::BYTES_SIZE]:,
59//     {
60//         Self::from_bytes(bytes, false)
61//     }
62// }
63
64// pub trait Bytes<Observer, Reference> {
65//     const BYTES_SIZE: usize;
66
67//     fn to_bytes(&self, endianness: bool) -> [u8; Self::BYTES_SIZE];
68//     fn to_le_bytes(&self) -> [u8; Self::BYTES_SIZE] {
69//         self.to_bytes(true)
70//     }
71//     fn to_be_bytes(&self) -> [u8; Self::BYTES_SIZE] {
72//         self.to_bytes(false)
73//     }
74//     fn from_bytes(bytes: [u8; Self::BYTES_SIZE], endianness: bool) -> Self;
75//     fn from_le_bytes(bytes: [u8; Self::BYTES_SIZE]) -> Self
76//     where
77//         Self: Sized,
78//     {
79//         Self::from_bytes(bytes, true)
80//     }
81//     fn from_be_bytes(bytes: [u8; Self::BYTES_SIZE]) -> Self
82//     where
83//         Self: Sized,
84//     {
85//         Self::from_bytes(bytes, false)
86//     }
87// }