Skip to main content

firmware_controller_macros/
lib.rs

1//! Procedural macros for `firmware-controller`. Do not use directly.
2//!
3//! See the [`firmware-controller`](https://docs.rs/firmware-controller) crate
4//! for documentation.
5
6#[cfg(not(any(feature = "embassy", feature = "tokio")))]
7compile_error!("Either the `embassy` or `tokio` feature must be enabled");
8
9#[cfg(all(feature = "embassy", feature = "tokio"))]
10compile_error!("The `embassy` and `tokio` features are mutually exclusive");
11
12use proc_macro::TokenStream;
13use syn::{parse_macro_input, punctuated::Punctuated, ItemMod, Meta, Token};
14
15mod controller;
16mod util;
17
18/// See the [`firmware-controller`](https://docs.rs/firmware-controller) crate
19/// for documentation.
20#[proc_macro_attribute]
21pub fn controller(attr: TokenStream, item: TokenStream) -> TokenStream {
22    let _args = parse_macro_input!(attr with Punctuated<Meta, Token![,]>::parse_terminated);
23
24    let input = parse_macro_input!(item as ItemMod);
25    controller::expand_module(input)
26        .unwrap_or_else(|e| e.to_compile_error())
27        .into()
28}