1use core::fmt::Debug;
2
3use crate::elf;
4use crate::endian;
5use crate::pod::Pod;
6
7/// A trait for generic access to [`elf::CompressionHeader32`] and [`elf::CompressionHeader64`].
8#[allow(missing_docs)]
9pub trait CompressionHeader: Debug + Pod {
10 type Word: Into<u64>;
11 type Endian: endian::Endian;
12
13 fn ch_type(&self, endian: Self::Endian) -> u32;
14 fn ch_size(&self, endian: Self::Endian) -> Self::Word;
15 fn ch_addralign(&self, endian: Self::Endian) -> Self::Word;
16}
17
18impl<Endian: endian::Endian> CompressionHeader for elf::CompressionHeader32<Endian> {
19 type Word = u32;
20 type Endian = Endian;
21
22 #[inline]
23 fn ch_type(&self, endian: Self::Endian) -> u32 {
24 self.ch_type.get(endian)
25 }
26
27 #[inline]
28 fn ch_size(&self, endian: Self::Endian) -> Self::Word {
29 self.ch_size.get(endian)
30 }
31
32 #[inline]
33 fn ch_addralign(&self, endian: Self::Endian) -> Self::Word {
34 self.ch_addralign.get(endian)
35 }
36}
37
38impl<Endian: endian::Endian> CompressionHeader for elf::CompressionHeader64<Endian> {
39 type Word = u64;
40 type Endian = Endian;
41
42 #[inline]
43 fn ch_type(&self, endian: Self::Endian) -> u32 {
44 self.ch_type.get(endian)
45 }
46
47 #[inline]
48 fn ch_size(&self, endian: Self::Endian) -> Self::Word {
49 self.ch_size.get(endian)
50 }
51
52 #[inline]
53 fn ch_addralign(&self, endian: Self::Endian) -> Self::Word {
54 self.ch_addralign.get(endian)
55 }
56}
57