#![doc(html_root_url = "https://docs.rs/efivar/2.0.0")]
#[macro_use]
extern crate bitflags;
#[macro_use]
extern crate lazy_static;
#[cfg(feature = "store")]
#[macro_use]
extern crate serde_derive;
#[cfg(windows)]
extern crate winapi;
pub mod efi;
#[cfg(feature = "store")]
pub mod store;
pub mod boot;
mod enumerator;
mod error;
pub mod push;
mod reader;
mod sys;
pub mod test_utils;
pub mod utils;
mod writer;
use boot::{BootVarReader, BootVarWriter};
pub use crate::enumerator::VarEnumerator;
pub use crate::reader::*;
pub use crate::writer::VarWriter;
pub use crate::error::Error;
pub type Result<T> = std::result::Result<T, Error>;
pub trait VarManager:
VarEnumerator + VarReader + VarWriter + BootVarReader + BootVarWriter
{
}
use crate::sys::SystemManager;
pub fn system() -> Box<dyn VarManager> {
Box::new(SystemManager::new())
}
#[cfg(feature = "store")]
pub fn file_store<P: Into<std::path::PathBuf>>(filename: P) -> Box<dyn VarManager> {
Box::new(store::FileStore::new(filename.into()))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
#[cfg(feature = "store")]
fn file_store_roundtrip() {
use crate::efi::{Variable, VariableFlags};
{
let mut store = file_store("doc-test.toml");
let value = vec![1, 2, 3, 4];
store
.write(
&Variable::new("BootOrder"),
VariableFlags::NON_VOLATILE,
&value,
)
.expect("Failed to write value in store");
let (data, attributes) = store.read(&Variable::new("BootOrder")).unwrap();
assert_eq!(attributes, VariableFlags::NON_VOLATILE);
assert_eq!(data, value);
}
std::fs::remove_file("doc-test.toml")
.expect("Failed to remove temporary file doc-test.toml");
}
#[test]
fn system_instantiate() {
system();
}
}