rebootinto_core/
lib.rs

1#![warn(rust_2018_idioms)]
2
3use efibootnext::Adapter;
4pub use efibootnext::LoadOption;
5pub use failure::Error;
6
7mod error;
8
9pub type Result<T> = std::result::Result<T, Error>;
10
11pub struct Backend {
12    adapter: Adapter,
13}
14
15impl Backend {
16    pub fn init() -> Result<Self> {
17        Ok(Self {
18            adapter: Adapter::default(),
19        })
20    }
21
22    pub fn load_options<'a>(&'a mut self) -> impl Iterator<Item = Result<LoadOption>> + 'a {
23        self.adapter.load_options()
24    }
25
26    pub fn reboot_into(&mut self, num: u16) -> Result<()> {
27        self.adapter
28            .set_boot_next(num)
29            .map_err(error::RebootIntoErrorKind::SetBootNextError)?;
30        simplereboot::reboot()
31            .map_err(|e| Error::from(e))
32            .map_err(error::RebootIntoErrorKind::RebootError)?;
33        Ok(())
34    }
35}