Skip to content

Conversation

@phip1611
Copy link
Member

@phip1611 phip1611 commented Jan 2, 2026

This PR prepares and implements a significant simplification of handling typical tasks with handles: printing a device path and using the component2 protocol.

  • impl Display for DevicePath and ScopedProtocol
  • add boot::open_protocol_[exclusive]if_exists() helpers (eventually replacing the base methods which we could deprecate)
  • add Handle::device_path() and Handle::component_name2()

This improves the convenience and ergonomics in every Rust uefi code base I've seen so far at work and in private projects.

Checklist

  • Sensible git history (for example, squash "typo" or "fix" commits). See the Rewriting History guide for help.
  • Update the changelog (if necessary)

@phip1611 phip1611 self-assigned this Jan 2, 2026
@phip1611 phip1611 force-pushed the handle-convenience branch 4 times, most recently from 8dd6b43 to b9c1651 Compare January 2, 2026 11:55
Clean up the mess and follow our convention:

- pub mod
- mod
- pub use
- use
This change is a prerequisite for the subsequent commit introducing
Display. Display already provides a to_string() method, so keeping the
existing name would cause ambiguity.

While fully qualified paths could be used to disambiguate, a dedicated
name is significantly more convenient. It also makes the distinction
between standard Rust strings and UEFI (UTF-16) strings explicit.
For device paths, it is very convenient to use the DevicePathToText
protocol to visualize/print the device path. By providing a
convenient Display impl, we improve the ergonomics of device paths
significantly and reducing boilerplate.
In practice, UEFI applications frequently need to extract additional
metadata from handles for logging, debugging, and user-facing selection.
The Device Path and Component Name 2 protocols provide this information,
but accessing them repeatedly requires non-trivial boilerplate.

This change introduces convenience helpers on Handle to streamline
common queries and improve ergonomics when working with these protocols.
crate::proto::device_path::DevicePath,
crate::proto::driver::ComponentName2,
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fix the cargo doc error:

Suggested change
#[cfg(doc)]
use crate::Status;

/// );
/// ```
#[cfg(feature = "alloc")]
pub fn component_name2(&self) -> Result<ScopedProtocol<ComponentName2>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the interests of keeping the API higher level, maybe we should call this just component_name?

/// cn2_prot.controller_name(handle, None, "en").unwrap()
/// );
/// ```
#[cfg(feature = "alloc")]
Copy link
Member

@nicholasbishop nicholasbishop Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this cfg needed?

/// .expect("should have device path");
/// log::info!("device path: {device_path}");
/// ```
#[cfg(feature = "alloc")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, seems like this should work without alloc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants