1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
use proc_macro::TokenStream; use syn::{parse_macro_input, DeriveInput}; mod inner; /// A little helper derive macro to implement the `libwifi::Addresses` trait /// for frames with either a DataHeader or a ManagementHeader. /// /// This macro is only designed for internal usage in the [libwifi](https://docs.rs/libwifi/latest/libwifi/) crate. /// /// How to use: /// ``` /// #[derive(Clone, Debug, AddressHeader)] /// pub struct AssociationRequest { /// pub header: ManagementHeader, /// pub beacon_interval: u16, /// pub capability_info: u16, /// pub station_info: StationInfo, /// } /// ``` /// /// The new generated code will look like this: /// ``` /// impl crate::Addresses for AssociationRequest { /// fn src(&self) -> Option<&MacAddress> { /// self.header.src() /// } /// /// fn dest(&self) -> &MacAddress { /// self.header.dest() /// } /// /// fn bssid(&self) -> Option<&MacAddress> { /// self.header.bssid() /// } /// } /// ``` #[proc_macro_derive(AddressHeader)] pub fn address_header(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); let toks = inner::address_header_inner(&input).unwrap_or_else(|err| err.to_compile_error()); toks.into() }