ms_codeview/syms/
offset_segment.rs1use super::*;
2
3#[repr(C)]
6#[derive(IntoBytes, FromBytes, Immutable, KnownLayout, Unaligned, Default, Clone, Copy, Eq)]
7pub struct OffsetSegment {
8 pub offset: U32<LE>,
10
11 pub segment: U16<LE>,
13}
14
15impl PartialEq for OffsetSegment {
16 #[inline]
17 fn eq(&self, other: &Self) -> bool {
18 self.as_u64() == other.as_u64()
19 }
20}
21
22impl PartialOrd for OffsetSegment {
23 #[inline]
24 fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
25 Some(self.cmp(other))
26 }
27}
28
29impl Ord for OffsetSegment {
30 #[inline]
31 fn cmp(&self, other: &Self) -> std::cmp::Ordering {
32 Ord::cmp(&self.as_u64(), &other.as_u64())
33 }
34}
35
36impl OffsetSegment {
37 #[inline]
39 pub fn offset(&self) -> u32 {
40 self.offset.get()
41 }
42
43 #[inline]
45 pub fn segment(&self) -> u16 {
46 self.segment.get()
47 }
48
49 #[inline]
52 pub fn as_tuple(&self) -> (u16, u32) {
53 (self.segment.get(), self.offset.get())
54 }
55
56 #[inline]
59 pub fn as_u64(&self) -> u64 {
60 ((self.segment.get() as u64) << 32) | (self.offset.get() as u64)
61 }
62}
63
64impl std::fmt::Display for OffsetSegment {
65 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
66 write!(f, "[{:04x}:{:08x}]", self.segment.get(), self.offset.get())
67 }
68}
69
70impl Debug for OffsetSegment {
71 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
72 <Self as std::fmt::Display>::fmt(self, f)
73 }
74}
75
76impl std::hash::Hash for OffsetSegment {
77 #[inline]
78 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
79 state.write_u16(self.segment());
80 state.write_u32(self.offset());
81 }
82}