Skip to content

Commit 9aa374e

Browse files
committed
tag: hide constructor details for Tags structure
Signed-off-by: Zhouqi Jiang <luojia@hust.edu.cn>
1 parent 84e658d commit 9aa374e

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/de.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,11 @@ impl DeviceTree {
8787
let structure_len = u32::from_be(self.header.size_dt_struct) as usize;
8888
let strings_addr = (u32::from_be(self.header.off_dt_strings) - HEADER_LEN) as usize;
8989
let strings_len = u32::from_be(self.header.size_dt_strings) as usize;
90-
Tags {
91-
structure: &self.data[structure_addr..structure_addr + structure_len],
92-
string_table: &self.data[strings_addr..strings_addr + strings_len],
93-
cur: 0,
94-
offset_from_file_begin: structure_addr,
95-
}
90+
Tags::new(
91+
&self.data[structure_addr..structure_addr + structure_len],
92+
&self.data[strings_addr..strings_addr + strings_len],
93+
structure_addr,
94+
)
9695
}
9796
}
9897

src/tag.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,21 @@ use crate::error::{Error, Result};
33

44
#[derive(Debug, Clone)]
55
pub struct Tags<'a> {
6-
pub(crate) structure: &'a [u8],
7-
pub(crate) string_table: &'a [u8],
8-
pub(crate) cur: usize,
9-
pub(crate) offset_from_file_begin: usize,
6+
structure: &'a [u8],
7+
string_table: &'a [u8],
8+
cur: usize,
9+
offset_from_file_begin: usize,
10+
}
11+
12+
impl<'a> Tags<'a> {
13+
pub fn new(structure: &'a [u8], string_table: &'a [u8], offset_from_file_begin: usize) -> Self {
14+
Tags {
15+
structure,
16+
string_table,
17+
cur: 0,
18+
offset_from_file_begin,
19+
}
20+
}
1021
}
1122

1223
#[inline]

0 commit comments

Comments
 (0)