Skip to content

Commit 3efd4c5

Browse files
authored
Merge pull request #254 from rust-osdev/misc
misc improvements
2 parents 0d30d12 + 3ce0ae2 commit 3efd4c5

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

.github/workflows/_build-rust.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,12 @@ jobs:
8989
- name: Code Formatting
9090
if: inputs.do-style-check
9191
run: cargo fmt --all -- --check
92-
- name: Code Style and Doc Style
92+
- name: "Code style: clippy"
9393
if: inputs.do-style-check
94-
run: |
95-
cargo doc --no-deps --document-private-items --features ${{ inputs.features }} --no-default-features
96-
cargo clippy --all-targets --features ${{ inputs.features }} --no-default-features
94+
run: cargo clippy --all-targets --features ${{ inputs.features }} --no-default-features
95+
- name: "Code style: rustdoc"
96+
if: inputs.do-style-check
97+
run: cargo doc --no-deps --document-private-items --features ${{ inputs.features }} --no-default-features
9798
- name: Unit Test
9899
run: cargo test --verbose
99100
- name: Unit Test with Miri

multiboot2/src/framebuffer.rs

+22-10
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ impl<'a> Reader<'a> {
2222
Self { buffer, off: 0 }
2323
}
2424

25-
fn read_u8(&mut self) -> u8 {
25+
/// Reads the next [`u8`] from the buffer and updates the internal pointer.
26+
///
27+
/// # Panic
28+
///
29+
/// Panics if the index is out of bounds.
30+
fn read_next_u8(&mut self) -> u8 {
2631
let val = self
2732
.buffer
2833
.get(self.off)
@@ -36,8 +41,15 @@ impl<'a> Reader<'a> {
3641
val
3742
}
3843

39-
fn read_u16(&mut self) -> u16 {
40-
self.read_u8() as u16 | (self.read_u8() as u16) << 8
44+
/// Reads the next [`u16`] from the buffer and updates the internal pointer.
45+
///
46+
/// # Panic
47+
///
48+
/// Panics if the index is out of bounds.
49+
fn read_next_u16(&mut self) -> u16 {
50+
let u16_lo = self.read_next_u8() as u16;
51+
let u16_hi = self.read_next_u8() as u16;
52+
(u16_hi << 8) | u16_lo
4153
}
4254

4355
const fn current_ptr(&self) -> *const u8 {
@@ -166,7 +178,7 @@ impl FramebufferTag {
166178
// TODO we can create a struct for this and implement
167179
// DynSizedStruct for it to leverage the already existing
168180
// functionality
169-
let num_colors = reader.read_u16();
181+
let num_colors = reader.read_next_u16();
170182

171183
let palette = {
172184
// Ensure the slice can be created without causing UB
@@ -182,12 +194,12 @@ impl FramebufferTag {
182194
Ok(FramebufferType::Indexed { palette })
183195
}
184196
FramebufferTypeId::RGB => {
185-
let red_pos = reader.read_u8(); // These refer to the bit positions of the LSB of each field
186-
let red_mask = reader.read_u8(); // And then the length of the field from LSB to MSB
187-
let green_pos = reader.read_u8();
188-
let green_mask = reader.read_u8();
189-
let blue_pos = reader.read_u8();
190-
let blue_mask = reader.read_u8();
197+
let red_pos = reader.read_next_u8(); // These refer to the bit positions of the LSB of each field
198+
let red_mask = reader.read_next_u8(); // And then the length of the field from LSB to MSB
199+
let green_pos = reader.read_next_u8();
200+
let green_mask = reader.read_next_u8();
201+
let blue_pos = reader.read_next_u8();
202+
let blue_mask = reader.read_next_u8();
191203
Ok(FramebufferType::RGB {
192204
red: FramebufferField {
193205
position: red_pos,

0 commit comments

Comments
 (0)