Skip to main content

ds_rom/rom/
library_entry.rs

1use std::fmt::Display;
2
3/// A library version string entry after the build info of an ARM9 program.
4pub struct LibraryEntry<'a> {
5    address: u32,
6    version_string: &'a str,
7}
8
9impl<'a> LibraryEntry<'a> {
10    /// Creates a new [`LibraryEntry`].
11    pub fn new(address: u32, version_string: &'a str) -> Self {
12        Self { address, version_string }
13    }
14
15    /// Returns the address of this [`LibraryEntry`].
16    pub fn address(&self) -> u32 {
17        self.address
18    }
19
20    /// Returns the version string of this [`LibraryEntry`].
21    pub fn version_string(&self) -> &'a str {
22        self.version_string
23    }
24
25    /// Returns a [`DisplayLibraryEntry`] which implements [`Display`].
26    pub fn display(&'a self, indent: usize) -> DisplayLibraryEntry<'a> {
27        DisplayLibraryEntry { entry: self, indent }
28    }
29}
30
31/// Can be used to display values inside [`LibraryEntry`].
32pub struct DisplayLibraryEntry<'a> {
33    entry: &'a LibraryEntry<'a>,
34    indent: usize,
35}
36
37impl Display for DisplayLibraryEntry<'_> {
38    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39        let i = " ".repeat(self.indent);
40        writeln!(f, "{i}Address .......... : {:#010x}", self.entry.address)?;
41        writeln!(f, "{i}Version string ... : {}", self.entry.version_string)?;
42        Ok(())
43    }
44}