pulley_interpreter/
imms.rs1use core::fmt;
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
9pub struct PcRelOffset(i32);
10
11#[cfg(feature = "arbitrary")]
12impl<'a> arbitrary::Arbitrary<'a> for PcRelOffset {
13 fn arbitrary(_u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
14 Ok(Self(0))
18 }
19}
20
21impl From<i32> for PcRelOffset {
22 #[inline]
23 fn from(offset: i32) -> Self {
24 PcRelOffset(offset)
25 }
26}
27
28impl From<PcRelOffset> for i32 {
29 #[inline]
30 fn from(offset: PcRelOffset) -> Self {
31 offset.0
32 }
33}
34
35impl fmt::Display for PcRelOffset {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 i32::from(*self).fmt(f)
38 }
39}
40
41#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
43pub struct U6(u8);
44
45impl U6 {
46 pub fn new(val: u8) -> Option<U6> {
48 if val << 2 >> 2 == val {
49 Some(U6(val))
50 } else {
51 None
52 }
53 }
54}
55
56#[cfg(feature = "arbitrary")]
57impl<'a> arbitrary::Arbitrary<'a> for U6 {
58 fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
59 let byte = u.arbitrary::<u8>()?;
60 Ok(U6(byte << 2 >> 2))
61 }
62}
63
64impl From<U6> for u8 {
65 #[inline]
66 fn from(val: U6) -> Self {
67 val.0
68 }
69}
70
71impl fmt::Display for U6 {
72 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
73 u8::from(*self).fmt(f)
74 }
75}