daicon_types/
index.rs

1use std::fmt::{self, Debug, Formatter};
2
3use bytemuck::{Pod, Zeroable};
4
5/// Index in a daicon table.
6#[derive(Pod, Zeroable, PartialEq, Hash, Default, Clone, Copy)]
7#[repr(C)]
8pub struct Index {
9    id: u32,
10    offset: u32,
11    size: u32,
12}
13
14impl Index {
15    /// Get the ID of the entry.
16    pub fn id(&self) -> Id {
17        Id(self.id)
18    }
19
20    pub fn set_id(&mut self, value: Id) {
21        self.id = value.0;
22    }
23
24    /// Get the offset of the entry.
25    pub fn offset(&self) -> u32 {
26        self.offset
27    }
28
29    pub fn set_offset(&mut self, value: u32) {
30        self.offset = value;
31    }
32
33    /// Get the size of the entry in bytes.
34    pub fn size(&self) -> u32 {
35        self.size
36    }
37
38    pub fn set_size(&mut self, value: u32) {
39        self.size = value;
40    }
41}
42
43impl Debug for Index {
44    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
45        write!(
46            f,
47            "Entry({:#010x}) {{ offset: {:#010x}, size: {} }}",
48            self.id, self.offset, self.size
49        )
50    }
51}
52
53/// Daicon entry identifier.
54#[derive(Hash, PartialEq, Eq, Clone, Copy)]
55#[repr(transparent)]
56pub struct Id(pub u32);
57
58impl Debug for Id {
59    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
60        write!(f, "Id({:#010x})", self.0)
61    }
62}