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>

source

pub fn with_buf(buf: &'a mut [MaybeUninit<u8>]) -> Self

Create a builder backed by a statically-sized buffer.

source

pub fn with_vec(v: &'a mut Vec<u8>) -> Self

Available on crate feature alloc only.

Create a builder backed by a Vec.

The Vec is cleared before use.

source

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.

source

pub fn finalize(self) -> Result<&'a DevicePath, BuildError>

Add an END_ENTIRE node and return the resulting DevicePath.

This method consumes the builder.

Trait Implementations§

source§

impl<'a> Debug for DevicePathBuilder<'a>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for DevicePathBuilder<'a>

§

impl<'a> Send for DevicePathBuilder<'a>

§

impl<'a> Sync for DevicePathBuilder<'a>

§

impl<'a> Unpin for DevicePathBuilder<'a>

§

impl<'a> !UnwindSafe for DevicePathBuilder<'a>

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> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

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

§

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>,

§

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.