Debian Codegraph @

third_party/rust/macho-unwind-info/src/raw/unaligned.rs

raw
1 use std::fmt::Debug;
2
3 use zerocopy_derive::{FromBytes, FromZeroes, Unaligned};
4
5 /// An unaligned little-endian `u32` value.
6 #[derive(
7 Unaligned, FromZeroes, FromBytes, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash,
8 )]
9 #[repr(transparent)]
10 pub struct U32([u8; 4]);
11
12 impl From<u32> for U32 {
13 fn from(n: u32) -> Self {
14 U32(n.to_le_bytes())
15 }
16 }
17
18 impl From<U32> for u32 {
19 fn from(n: U32) -> Self {
20 u32::from_le_bytes(n.0)
21 }
22 }
23
24 impl Debug for U32 {
25 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26 u32::fmt(&(*self).into(), f)
27 }
28 }
29
30 /// An unaligned little-endian `u16` value.
31 #[derive(
32 Unaligned, FromZeroes, FromBytes, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash,
33 )]
34 #[repr(transparent)]
35 pub struct U16([u8; 2]);
36
37 impl From<u16> for U16 {
38 fn from(n: u16) -> Self {
39 U16(n.to_le_bytes())
40 }
41 }
42
43 impl From<U16> for u16 {
44 fn from(n: U16) -> Self {
45 u16::from_le_bytes(n.0)
46 }
47 }
48
49 impl Debug for U16 {
50 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51 u16::fmt(&(*self).into(), f)
52 }
53 }