From 976d54eea45240d6c9156743335e3a657c4a64c9 Mon Sep 17 00:00:00 2001 From: fox0 <15684995+fox0@users.noreply.github.com> Date: Sun, 11 May 2025 11:09:56 +0700 Subject: [PATCH] uefi: `system:: with_*` now take mutably closure --- uefi/CHANGELOG.md | 2 ++ uefi/src/system.rs | 42 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/uefi/CHANGELOG.md b/uefi/CHANGELOG.md index fbd8c4c3a..838e1173c 100644 --- a/uefi/CHANGELOG.md +++ b/uefi/CHANGELOG.md @@ -6,6 +6,8 @@ ## Changed - **Breaking:** `boot::stall` now take `core::time::Duration` instead of `usize`. - `table::cfg::*_GUID` constants now deprecated. Use `ConfigTableEntry::*_GUID` instead. +- `system::with_config_table`, `system::with_stdin`, `system::with_stdout` and `system::with_stderr` + now take mutably closure. # uefi - 0.35.0 (2025-05-04) diff --git a/uefi/src/system.rs b/uefi/src/system.rs index 3f8ff8442..c6603e339 100644 --- a/uefi/src/system.rs +++ b/uefi/src/system.rs @@ -68,9 +68,9 @@ pub fn uefi_revision() -> Revision { /// } /// }); /// ``` -pub fn with_config_table(f: F) -> R +pub fn with_config_table(mut f: F) -> R where - F: Fn(&[ConfigTableEntry]) -> R, + F: FnMut(&[ConfigTableEntry]) -> R, { let st = table::system_table_raw_panicking(); // SAFETY: valid per requirements of `set_system_table`. @@ -83,6 +83,7 @@ where } else { unsafe { slice::from_raw_parts(ptr, len) } }; + f(slice) } @@ -92,9 +93,9 @@ where /// /// This function will panic if called after exiting boot services, or if stdin /// is not available. -pub fn with_stdin(f: F) -> R +pub fn with_stdin(mut f: F) -> R where - F: Fn(&mut Input) -> R, + F: FnMut(&mut Input) -> R, { let st = table::system_table_raw_panicking(); // SAFETY: valid per requirements of `set_system_table`. @@ -118,9 +119,9 @@ where /// /// This function will panic if called after exiting boot services, or if stdout /// is not available. -pub fn with_stdout(f: F) -> R +pub fn with_stdout(mut f: F) -> R where - F: Fn(&mut Output) -> R, + F: FnMut(&mut Output) -> R, { let st = table::system_table_raw_panicking(); // SAFETY: valid per requirements of `set_system_table`. @@ -144,9 +145,9 @@ where /// /// This function will panic if called after exiting boot services, or if stderr /// is not available. -pub fn with_stderr(f: F) -> R +pub fn with_stderr(mut f: F) -> R where - F: Fn(&mut Output) -> R, + F: FnMut(&mut Output) -> R, { let st = table::system_table_raw_panicking(); // SAFETY: valid per requirements of `set_system_table`. @@ -163,3 +164,28 @@ where f(stderr) } + +#[cfg(test)] +mod tests { + use super::*; + + #[allow(dead_code)] + #[allow(clippy::assertions_on_constants)] + fn with_config_table_compile_test() { + assert!(false, "compile test only"); + + let mut acpi2_address = None; + + with_config_table(|slice| { + for i in slice { + match i.guid { + ConfigTableEntry::ACPI2_GUID => { + acpi2_address = Some(i.address); + break; + } + _ => {} + } + } + }); + } +}