Skip to content

uefi: change Fn closure to FnMut #1662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
36 changes: 28 additions & 8 deletions uefi/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ pub fn uefi_revision() -> Revision {

/// Call `f` with a slice of [`ConfigTableEntry`]. Each entry provides access to
/// a vendor-specific table.
pub fn with_config_table<F, R>(f: F) -> R
pub fn with_config_table<F, R>(mut f: F) -> R
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document these changes in the changelog

where
F: Fn(&[ConfigTableEntry]) -> R,
F: FnMut(&[ConfigTableEntry]) -> R,
{
let st = table::system_table_raw_panicking();
// SAFETY: valid per requirements of `set_system_table`.
Expand All @@ -75,9 +75,9 @@ where
///
/// This function will panic if called after exiting boot services, or if stdin
/// is not available.
pub fn with_stdin<F, R>(f: F) -> R
pub fn with_stdin<F, R>(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`.
Expand All @@ -101,9 +101,9 @@ where
///
/// This function will panic if called after exiting boot services, or if stdout
/// is not available.
pub fn with_stdout<F, R>(f: F) -> R
pub fn with_stdout<F, R>(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`.
Expand All @@ -127,9 +127,9 @@ where
///
/// This function will panic if called after exiting boot services, or if stderr
/// is not available.
pub fn with_stderr<F, R>(f: F) -> R
pub fn with_stderr<F, R>(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`.
Expand All @@ -146,3 +146,23 @@ where

f(stderr)
}

#[cfg(test)]
mod tests {
use super::*;
use crate::table::cfg::ACPI2_GUID;

// compile test only
#[allow(dead_code)]
fn with_config_table_compile_test() {
let mut address_acpi2 = None;
with_config_table(|slice| {
for i in slice {
match i.guid {
ACPI2_GUID => address_acpi2 = Some(i.address),
_ => {}
}
}
});
}
}
Loading