uefi/proto/boot_policy.rs
1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! Module for the [`BootPolicy`] helper type.
4
5use uefi_raw::Boolean;
6
7/// The UEFI boot policy is a property that influences the behaviour of
8/// various UEFI functions that load files (typically UEFI images).
9///
10/// This type is not ABI compatible. On the ABI level, this corresponds to
11/// a [`Boolean`].
12#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialEq, PartialOrd)]
13pub enum BootPolicy {
14 /// Indicates that the request originates from the boot manager, and that
15 /// the boot manager is attempting to load the provided `file_path` as a
16 /// boot selection.
17 ///
18 /// Boot selection refers to what a user has chosen in the (GUI) boot menu.
19 ///
20 /// This corresponds to the underlying [`Boolean`] being `true`.
21 BootSelection,
22 /// The provided `file_path` must match an exact file to be loaded.
23 ///
24 /// This corresponds to the underlying [`Boolean`] being `false`.
25 #[default]
26 ExactMatch,
27}
28
29impl From<BootPolicy> for Boolean {
30 fn from(value: BootPolicy) -> Self {
31 match value {
32 BootPolicy::BootSelection => Self::TRUE,
33 BootPolicy::ExactMatch => Self::FALSE,
34 }
35 }
36}
37
38impl From<Boolean> for BootPolicy {
39 fn from(value: Boolean) -> Self {
40 let boolean: bool = value.into();
41 match boolean {
42 true => Self::BootSelection,
43 false => Self::ExactMatch,
44 }
45 }
46}
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn boot_policy() {
54 assert_eq!(
55 BootPolicy::try_from(Boolean::TRUE).unwrap(),
56 BootPolicy::BootSelection
57 );
58 assert_eq!(
59 BootPolicy::try_from(Boolean::FALSE).unwrap(),
60 BootPolicy::ExactMatch
61 );
62 assert_eq!(Boolean::from(BootPolicy::BootSelection), Boolean::TRUE);
63 assert_eq!(Boolean::from(BootPolicy::ExactMatch), Boolean::FALSE);
64 }
65}