Struct uefi::proto::device_path::build::DevicePathBuilder
source · pub struct DevicePathBuilder<'a> { /* private fields */ }Expand description
A builder for DevicePaths.
The builder can be constructed with either a fixed-length buffer or
(if the alloc feature is enabled) a Vec.
Nodes are added via the push method. To construct a node, use one
of the structs in these submodules:
A node can also be constructed by copying a node from an existing device path.
To complete a path, call the finalize method. This adds an
END_ENTIRE node and returns a DevicePath reference tied to
the lifetime of the buffer the builder was constructed with.
Examples
use core::mem::MaybeUninit;
use uefi::guid;
use uefi::proto::device_path::DevicePath;
use uefi::proto::device_path::build;
let mut buf = [MaybeUninit::uninit(); 256];
let path: &DevicePath = build::DevicePathBuilder::with_buf(&mut buf)
.push(&build::acpi::Acpi {
hid: 0x41d0_0a03,
uid: 0x0000_0000,
})?
.push(&build::hardware::Pci {
function: 0x00,
device: 0x1f,
})?
.push(&build::hardware::Vendor {
vendor_guid: guid!("15e39a00-1dd2-1000-8d7f-00a0c92408fc"),
vendor_defined_data: &[1, 2, 3, 4, 5, 6],
})?
.finalize()?;
assert_eq!(path.node_iter().count(), 3);Implementations§
source§impl<'a> DevicePathBuilder<'a>
impl<'a> DevicePathBuilder<'a>
sourcepub fn with_buf(buf: &'a mut [MaybeUninit<u8>]) -> Self
pub fn with_buf(buf: &'a mut [MaybeUninit<u8>]) -> Self
Create a builder backed by a statically-sized buffer.
sourcepub fn with_vec(v: &'a mut Vec<u8>) -> Self
Available on crate feature alloc only.
pub fn with_vec(v: &'a mut Vec<u8>) -> Self
alloc only.Create a builder backed by a Vec.
The Vec is cleared before use.
sourcepub fn push(self, node: &dyn BuildNode) -> Result<Self, BuildError>
pub fn push(self, node: &dyn BuildNode) -> Result<Self, BuildError>
Add a node to the device path.
An error will be returned if an END_ENTIRE node is passed to
this function, as that node will be added when finalize is
called.
sourcepub fn finalize(self) -> Result<&'a DevicePath, BuildError>
pub fn finalize(self) -> Result<&'a DevicePath, BuildError>
Add an END_ENTIRE node and return the resulting DevicePath.
This method consumes the builder.