1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct FWord(i16);
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct UfWord(u16);
impl FWord {
pub fn new(raw: i16) -> Self {
Self(raw)
}
pub fn to_i16(self) -> i16 {
self.0
}
pub fn to_be_bytes(self) -> [u8; 2] {
self.0.to_be_bytes()
}
}
impl UfWord {
pub fn new(raw: u16) -> Self {
Self(raw)
}
pub fn to_u16(self) -> u16 {
self.0
}
pub fn to_be_bytes(self) -> [u8; 2] {
self.0.to_be_bytes()
}
}
impl std::fmt::Display for FWord {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl std::fmt::Display for UfWord {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.0.fmt(f)
}
}
crate::newtype_scalar!(FWord, [u8; 2]);
crate::newtype_scalar!(UfWord, [u8; 2]);