Skip to main content

BLSEntry

Struct BLSEntry 

Source
pub struct BLSEntry {
Show 16 fields pub title: Option<BLSValue>, pub version: Option<BLSValue>, pub machine_id: Option<BLSValue>, pub sort_key: Option<BLSValue>, pub linux: BLSValue, pub efi: Option<BLSValue>, pub initrd: Vec<BLSValue>, pub options: Vec<BLSValue>, pub devicetree: Option<BLSValue>, pub devicetree_overlay: Option<BLSValue>, pub architecture: Option<BLSValue>, pub grub_hotkey: Option<BLSValue>, pub grub_users: Option<BLSValue>, pub grub_class: Vec<BLSValue>, pub grub_arg: Option<BLSValue>, pub comments: Vec<String>,
}
Expand description

A parsed Boot Loader Spec (Type #1) entry. Holds all standard and Fedora/GRUB keys.

Use BLSEntry::parse to parse from text and BLSEntry::render to serialize.

Fields§

§title: Option<BLSValue>

Optional title (e.g. from PRETTY_NAME).

§version: Option<BLSValue>

Optional version (e.g. kernel version).

§machine_id: Option<BLSValue>

Optional machine ID.

§sort_key: Option<BLSValue>

Optional sort key.

§linux: BLSValue

Kernel image path; always present (empty if entry is efi-only).

§efi: Option<BLSValue>

Optional EFI program path.

§initrd: Vec<BLSValue>

Initrd paths (multiple allowed).

§options: Vec<BLSValue>

Kernel/command-line options (multiple allowed).

§devicetree: Option<BLSValue>

Optional devicetree path.

§devicetree_overlay: Option<BLSValue>

Optional devicetree overlay path(s).

§architecture: Option<BLSValue>

Optional architecture.

§grub_hotkey: Option<BLSValue>

Fedora/GRUB: optional hotkey.

§grub_users: Option<BLSValue>

Fedora/GRUB: optional users.

§grub_class: Vec<BLSValue>

Fedora/GRUB: menu classes (multiple allowed).

§grub_arg: Option<BLSValue>

Fedora/GRUB: optional extra argument.

§comments: Vec<String>

Full-line comments; when rendering they are output at the top.

Implementations§

Source§

impl BLSEntry

Source

pub fn new() -> BLSEntry

Creates an empty entry. Optional fields are None; linux is an empty string.

Source§

impl BLSEntry

Source

pub fn parse(buffer: &str) -> Result<BLSEntry, String>

Parses a BLS entry from UTF-8 text. The entry must contain at least one of linux or efi. Returns an error if required keys are missing or an unknown key is encountered. Comment lines are collected in comments and output at the header when rendering.

§Examples
use boot_loader_spec::{BLSEntry, BLSValue};

let text = "title Fedora\nlinux /vmlinuz\noptions root=/dev/sda1";
let entry = BLSEntry::parse(text).unwrap();
assert_eq!(entry.title.as_ref().and_then(|v| match v { BLSValue::Value(s) => Some(s.as_str()), _ => None }).unwrap(), "Fedora");
assert!(matches!(&entry.linux, BLSValue::Value(p) if p == "/vmlinuz"));
Source

pub fn render(&self) -> String

Serializes the entry to BLS text (UTF-8, newline-separated lines). Comments are output first.

§Examples
use boot_loader_spec::{BLSEntry, BLSKey, ValueSetPolicy};

let mut entry = BLSEntry::new();
entry.set(BLSKey::Linux, "/vmlinuz".into(), None, ValueSetPolicy::ReplaceAll);
entry.set(BLSKey::Title, "My OS".into(), None, ValueSetPolicy::ReplaceAll);
let out = entry.render();
assert!(out.contains("linux /vmlinuz"));
assert!(out.contains("title My OS"));
Source

pub fn set( &mut self, key: BLSKey, value: String, comment: Option<String>, set_policy: ValueSetPolicy, )

Sets a value for the given key. For multi-value keys (initrd, options, grub_class), set_policy controls append, prepend, replace, or insert-at-index.

§Panics

May panic if ValueSetPolicy::InsertAt(i) is used with an index out of range.

Source

pub fn clear(&mut self, key: BLSKey)

Clears the given key. For BLSKey::Linux, sets the value to an empty string (key remains present). Other keys become None or empty.

Trait Implementations§

Source§

impl Debug for BLSEntry

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for BLSEntry

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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, 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.