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
use std::fmt;
#[derive(Copy,Clone,PartialEq,Eq)]
pub enum VarSize {
Bits64(u64),
Bits32(u32),
Bits16(u16)
}
impl fmt::Debug for VarSize {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&VarSize::Bits64(ref v) => write!(f, "64bit {:#016X}", v.clone()),
&VarSize::Bits32(ref v) => write!(f, "32bit {:#016X}", v.clone()),
&VarSize::Bits16(ref v) => write!(f, "16bit {:#016X}", v.clone()),
}
}
}
impl Into<usize> for VarSize {
#[inline(always)]
fn into(self) -> usize {
match self {
VarSize::Bits64(x) => x as usize,
VarSize::Bits32(x) => x as usize,
VarSize::Bits16(x) => x as usize,
}
}
}
impl From<u16> for VarSize {
#[inline(always)]
fn from(x: u16) -> VarSize {
VarSize::Bits16(x)
}
}
impl From<u32> for VarSize {
#[inline(always)]
fn from(x: u32) -> VarSize {
VarSize::Bits32(x)
}
}
impl From<u64> for VarSize {
#[inline(always)]
fn from(x: u64) -> VarSize {
VarSize::Bits64(x)
}
}