Skip to main content

create_typed_capability

Macro create_typed_capability 

Source
macro_rules! create_typed_capability {
    ($var:ident, $type:ident: $($T:path),+ $(,)?) => { ... };
}
Expand description

Create a struct that implements the given capability traits.

Unlike create_capability!, this macro creates an instance of a struct with a visibly named type. Use this when you need to name the capability type, such as when passing it to a component’s static buffer macro.

§Usage Example


create_typed_capability!(proc_cap, ProcCapForManager: ProcessManagementCapability);

let manager = components::manager::ManagerComponent::new(
    board_kernel,
    mux_alarm,
    proc_cap,
)
.finalize(components::manager_component_static!(
    AlarmHw,
    ProcCapForManager,
));

§Difference from create_capability!()

create_typed_capability!() creates a visibly named type, whereas create_capability! does not. If possible, use create_capability!. However, for components that need to name the type for static constructors, use create_typed_capability!() to create the struct that is used in that macro expansion and in the component finalize() method.

§Supporting Multiple Capabilities

Some type signatures require multiple capabilities. This macro supports declaring multiple capabilities. For example:

kernel::create_typed_capability!(process_console_cap, ProcessConsoleCap:
    kernel::capabilities::ProcessManagementCapability,
    kernel::capabilities::ProcessStartCapability
);

§Restrictions

This helper macro cannot be called from #![forbid(unsafe_code)] crates, and is used by trusted code to generate a capability type.

§Safety

This macro can only be used in a context that is allowed to use unsafe. Specifically, an internal allow(unsafe_code) directive will conflict with any forbid(unsafe_code) at the crate or block level.