Struct SystemdBootConf

Source
pub struct SystemdBootConf {
    pub efi_mount: Box<Path>,
    pub entries_path: Box<Path>,
    pub loader_path: Box<Path>,
    pub entries: Vec<Entry>,
    pub loader_conf: LoaderConf,
}

Fields§

§efi_mount: Box<Path>§entries_path: Box<Path>§loader_path: Box<Path>§entries: Vec<Entry>§loader_conf: LoaderConf

Implementations§

Source§

impl SystemdBootConf

Source

pub fn new<P: Into<PathBuf>>(efi_mount: P) -> Result<Self, Error>

Examples found in repository?
examples/list.rs (line 7)
6pub fn main() {
7    let manager = match SystemdBootConf::new("/boot/efi") {
8        Ok(manager) => manager,
9        Err(why) => {
10            eprintln!("failed to get systemd-boot info: {}", why);
11            exit(1);
12        }
13    };
14
15    println!(
16        "loader:\n  default: {:?}\n  timeout: {:?}",
17        manager.loader_conf.default, manager.loader_conf.timeout
18    );
19
20    for entry in manager.entries {
21        println!(
22            "  id: {}\n    title: {}\n    linux: {}\n    initrd: {:?}\n    options: {:?}",
23            entry.id, entry.title, entry.linux, entry.initrd, entry.options
24        );
25    }
26}
More examples
Hide additional examples
examples/timeout.rs (line 7)
6pub fn main() {
7    let mut manager = match SystemdBootConf::new("/boot/efi") {
8        Ok(manager) => manager,
9        Err(why) => {
10            eprintln!("failed to get systemd-boot info: {}", why);
11            exit(1);
12        }
13    };
14
15    manager.loader_conf.timeout = Some(10);
16    if let Err(why) = manager.overwrite_loader_conf() {
17        eprintln!("failed to overwrite systemd-boot loader: {}", why);
18        exit(1);
19    }
20
21    println!("successfully overwrote loader conf");
22    if let Err(why) = manager.load_conf() {
23        eprintln!("failed to reload systemd-boot loader conf: {}", why);
24        exit(1);
25    }
26
27    println!(
28        "loader:\n  default: {:?}\n  timeout: {:?}",
29        manager.loader_conf.default, manager.loader_conf.timeout
30    );
31}
Source

pub fn current_entry(&self) -> Option<&Entry>

Find the boot entry which matches the current boot

§Implementation

The current boot option is determined by a matching the entry’s initd and options to /proc/cmdline.

Source

pub fn default_entry_exists(&self) -> DefaultState

Validate that the default entry exists.

Source

pub fn entry_exists(&self, entry: &str) -> bool

Validates that an entry exists with this name.

Source

pub fn get(&self, entry: &str) -> Option<&Entry>

Get the entry that corresponds to the given name.

Source

pub fn get_mut(&mut self, entry: &str) -> Option<&mut Entry>

Get a mutable entry that corresponds to the given name.

Source

pub fn load_conf(&mut self) -> Result<(), Error>

Attempt to re-read the loader configuration.

Examples found in repository?
examples/timeout.rs (line 22)
6pub fn main() {
7    let mut manager = match SystemdBootConf::new("/boot/efi") {
8        Ok(manager) => manager,
9        Err(why) => {
10            eprintln!("failed to get systemd-boot info: {}", why);
11            exit(1);
12        }
13    };
14
15    manager.loader_conf.timeout = Some(10);
16    if let Err(why) = manager.overwrite_loader_conf() {
17        eprintln!("failed to overwrite systemd-boot loader: {}", why);
18        exit(1);
19    }
20
21    println!("successfully overwrote loader conf");
22    if let Err(why) = manager.load_conf() {
23        eprintln!("failed to reload systemd-boot loader conf: {}", why);
24        exit(1);
25    }
26
27    println!(
28        "loader:\n  default: {:?}\n  timeout: {:?}",
29        manager.loader_conf.default, manager.loader_conf.timeout
30    );
31}
Source

pub fn load_entries(&mut self) -> Result<(), Error>

Attempt to load all of the available entries in the system.

Source

pub fn overwrite_loader_conf(&self) -> Result<(), Error>

Overwrite the conf file with stored values.

Examples found in repository?
examples/timeout.rs (line 16)
6pub fn main() {
7    let mut manager = match SystemdBootConf::new("/boot/efi") {
8        Ok(manager) => manager,
9        Err(why) => {
10            eprintln!("failed to get systemd-boot info: {}", why);
11            exit(1);
12        }
13    };
14
15    manager.loader_conf.timeout = Some(10);
16    if let Err(why) = manager.overwrite_loader_conf() {
17        eprintln!("failed to overwrite systemd-boot loader: {}", why);
18        exit(1);
19    }
20
21    println!("successfully overwrote loader conf");
22    if let Err(why) = manager.load_conf() {
23        eprintln!("failed to reload systemd-boot loader conf: {}", why);
24        exit(1);
25    }
26
27    println!(
28        "loader:\n  default: {:?}\n  timeout: {:?}",
29        manager.loader_conf.default, manager.loader_conf.timeout
30    );
31}
Source

pub fn overwrite_entry_conf(&self, entry: &str) -> Result<(), Error>

Overwrite the entry conf for the given entry.

Trait Implementations§

Source§

impl Clone for SystemdBootConf

Source§

fn clone(&self) -> SystemdBootConf

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SystemdBootConf

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.