Skip to content

Commit 976d54e

Browse files
committed
uefi: system:: with_* now take mutably closure
1 parent 17ff62b commit 976d54e

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

uefi/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
## Changed
77
- **Breaking:** `boot::stall` now take `core::time::Duration` instead of `usize`.
88
- `table::cfg::*_GUID` constants now deprecated. Use `ConfigTableEntry::*_GUID` instead.
9+
- `system::with_config_table`, `system::with_stdin`, `system::with_stdout` and `system::with_stderr`
10+
now take mutably closure.
911

1012

1113
# uefi - 0.35.0 (2025-05-04)

uefi/src/system.rs

+34-8
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ pub fn uefi_revision() -> Revision {
6868
/// }
6969
/// });
7070
/// ```
71-
pub fn with_config_table<F, R>(f: F) -> R
71+
pub fn with_config_table<F, R>(mut f: F) -> R
7272
where
73-
F: Fn(&[ConfigTableEntry]) -> R,
73+
F: FnMut(&[ConfigTableEntry]) -> R,
7474
{
7575
let st = table::system_table_raw_panicking();
7676
// SAFETY: valid per requirements of `set_system_table`.
@@ -83,6 +83,7 @@ where
8383
} else {
8484
unsafe { slice::from_raw_parts(ptr, len) }
8585
};
86+
8687
f(slice)
8788
}
8889

@@ -92,9 +93,9 @@ where
9293
///
9394
/// This function will panic if called after exiting boot services, or if stdin
9495
/// is not available.
95-
pub fn with_stdin<F, R>(f: F) -> R
96+
pub fn with_stdin<F, R>(mut f: F) -> R
9697
where
97-
F: Fn(&mut Input) -> R,
98+
F: FnMut(&mut Input) -> R,
9899
{
99100
let st = table::system_table_raw_panicking();
100101
// SAFETY: valid per requirements of `set_system_table`.
@@ -118,9 +119,9 @@ where
118119
///
119120
/// This function will panic if called after exiting boot services, or if stdout
120121
/// is not available.
121-
pub fn with_stdout<F, R>(f: F) -> R
122+
pub fn with_stdout<F, R>(mut f: F) -> R
122123
where
123-
F: Fn(&mut Output) -> R,
124+
F: FnMut(&mut Output) -> R,
124125
{
125126
let st = table::system_table_raw_panicking();
126127
// SAFETY: valid per requirements of `set_system_table`.
@@ -144,9 +145,9 @@ where
144145
///
145146
/// This function will panic if called after exiting boot services, or if stderr
146147
/// is not available.
147-
pub fn with_stderr<F, R>(f: F) -> R
148+
pub fn with_stderr<F, R>(mut f: F) -> R
148149
where
149-
F: Fn(&mut Output) -> R,
150+
F: FnMut(&mut Output) -> R,
150151
{
151152
let st = table::system_table_raw_panicking();
152153
// SAFETY: valid per requirements of `set_system_table`.
@@ -163,3 +164,28 @@ where
163164

164165
f(stderr)
165166
}
167+
168+
#[cfg(test)]
169+
mod tests {
170+
use super::*;
171+
172+
#[allow(dead_code)]
173+
#[allow(clippy::assertions_on_constants)]
174+
fn with_config_table_compile_test() {
175+
assert!(false, "compile test only");
176+
177+
let mut acpi2_address = None;
178+
179+
with_config_table(|slice| {
180+
for i in slice {
181+
match i.guid {
182+
ConfigTableEntry::ACPI2_GUID => {
183+
acpi2_address = Some(i.address);
184+
break;
185+
}
186+
_ => {}
187+
}
188+
}
189+
});
190+
}
191+
}

0 commit comments

Comments
 (0)