Attribute Macro uefi_macros::unsafe_protocol

source ·
#[unsafe_protocol]
Expand description

Attribute macro for marking structs as UEFI protocols.

The macro takes one argument, either a GUID string or the path to a Guid constant.

The macro can only be applied to a struct. It implements the Protocol trait and the unsafe Identify trait for the struct.

Safety

The caller must ensure that the correct GUID is attached to the type. An incorrect GUID could lead to invalid casts and other unsound behavior.

Example

use uefi::{Guid, Identify, guid};
use uefi::proto::unsafe_protocol;

#[unsafe_protocol("12345678-9abc-def0-1234-56789abcdef0")]
struct ExampleProtocol1 {}

const PROTO_GUID: Guid = guid!("12345678-9abc-def0-1234-56789abcdef0");
#[unsafe_protocol(PROTO_GUID)]
struct ExampleProtocol2 {}

assert_eq!(ExampleProtocol1::GUID, PROTO_GUID);
assert_eq!(ExampleProtocol2::GUID, PROTO_GUID);