Skip to content

Commit

Permalink
macros(OptsBuilder): mark mask via builder(mask)
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Dec 5, 2023
1 parent b0aaddb commit d5ea8d7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 20 additions & 3 deletions crates/oxi-macros/src/derive_opts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::cmp::Ordering;

use proc_macro::TokenStream;
use proc_macro2::TokenTree;
use quote::quote;
use syn::*;

Expand Down Expand Up @@ -145,11 +146,27 @@ pub fn derive_opts_builder(attr: TokenStream) -> TokenStream {
/// Returns `true` if the field has the `mask` attribute.
fn is_mask(field: &Field) -> bool {
for attr in &field.attrs {
let Meta::Path(path) = &attr.meta else { continue };
let Meta::List(list) = &attr.meta else { continue };

if path.is_ident("mask") {
return true;
if !list.path.is_ident("builder") {
continue;
}

let mut tokens = list.tokens.clone().into_iter();

let Some(TokenTree::Ident(first_token)) = tokens.next() else {
continue;
};

if first_token != "mask" {
continue;
}

if tokens.next().is_some() {
continue;
}

return true;
}

false
Expand Down
2 changes: 1 addition & 1 deletion crates/oxi-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use syn::parse_macro_input;
mod derive_opts;

/// TODO: docs
#[proc_macro_derive(OptsBuilder, attributes(mask))]
#[proc_macro_derive(OptsBuilder, attributes(builder))]
pub fn derive_opts_builder(input: TokenStream) -> TokenStream {
derive_opts::derive_opts_builder(input)
}
Expand Down

0 comments on commit d5ea8d7

Please sign in to comment.