patina_macro 20.0.3

Proc-macro crate for the UEFI Software Development Kit (SDK).
Documentation
# Patina Macro Crate


`patina_macro` hosts the procedural macros used in Patina. This includes those that support the Patina component
system, service registration, guided HOB parsing, on-target test discovery, and more. The
[`patina`](https://crates.io/crates/patina) crate re-export these macros, so most cases only need a dependency on
`patina`.

## Notable Macros


### `#[component]`


- Applied to impl blocks containing an `entry_point` method to define components.
- Validates parameters at compile time and generates the boilerplate required to satisfy `patina::component::IntoComponent`.
- The `entry_point` method must consume `self` and takes dependency-injected parameters implementing `ComponentParam`.
- Compile-time validation detects parameter conflicts such as duplicate `ConfigMut<T>` or mixing `Config<T>` and `ConfigMut<T>`.

```rust
use patina::component::{component, params::Config};

struct BoardInit;

#[component]

impl BoardInit {
    fn entry_point(self, config: Config<u32>) -> patina::error::Result<()> {
        patina::log::info!("Selected profile: {}", *config);
        Ok(())
    }
}
```

### `#[derive(IntoService)]`


- Implements `patina::component::service::IntoService` for a concrete provider.
- Specify one or more service interfaces with `#[service(dyn TraitA, dyn TraitB)]`.

> Note: The macro leaks the provider once and registers `'static` references so every component receives the same
> backing instance.

```rust
use patina::component::service::IntoService;

trait Uart {
    fn write(&self, bytes: &[u8]) -> patina::error::Result<()>;
}

#[derive(IntoService)]

#[service(dyn Uart)]

struct SerialPort;

impl Uart for SerialPort {
    fn write(&self, bytes: &[u8]) -> patina::error::Result<()> {
        patina::log::info!("UART: {:?}", bytes);
        Ok(())
    }
}
```

### `#[derive(FromHob)]`


- Bridges GUIDed Hand-Off Blocks (HOBs) into strongly typed Rust values.
- Attach the GUID with `#[hob = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"]`.

```rust
use patina::component::hob::FromHob;

#[derive(FromHob, zerocopy_derive::FromBytes)]

#[repr(C)]

#[hob = "8be4df61-93ca-11d2-aa0d-00e098032b8c"]

struct FirmwareVolumeHeader {
    length: u32,
    revision: u16,
}
```

### `#[patina_test]`


- Registers a function with the Patina test runner that executes inside the DXE environment.
- Gate platform-specific tests with `cfg_attr` so they only compile when the runner is active.
- Optional attributes:
  - `#[should_fail]` or `#[should_fail = "message"]`
  - `#[skip]`

```rust
use patina::test::{patina_test, Result};

#[cfg_attr(target_arch = "x86_64", patina_test)]

fn spi_smoke_test() -> Result {
    patina::u_assert!(spi::probe(), "SPI controller missing");
    Ok(())
}

#[patina_test]

#[should_fail = "Expected watchdog trip"]

fn watchdog_negative_path() -> Result {
    patina::u_assert_eq!(watchdog::arm(), Err("trip"));
    Ok(())
}
```