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: BLSValueKernel 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
impl BLSEntry
Sourcepub fn parse(buffer: &str) -> Result<BLSEntry, String>
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"));Sourcepub fn render(&self) -> String
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"));Sourcepub fn set(
&mut self,
key: BLSKey,
value: String,
comment: Option<String>,
set_policy: ValueSetPolicy,
)
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.