diff --git a/psopacket/src/lib.rs b/psopacket/src/lib.rs index 60c7459..48f10c1 100644 --- a/psopacket/src/lib.rs +++ b/psopacket/src/lib.rs @@ -342,6 +342,7 @@ pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream { let args = parse_macro_input!(attr as syn::AttributeArgs); let mut cmd = 0; let mut flag = true; + let mut manual_flag = false; for a in args { match &a { NestedMeta::Lit(lit) => { @@ -353,6 +354,10 @@ pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream { if let syn::Meta::Path(syn::Path {segments, ..}) = k { match segments[0].ident.to_string().as_str() { "no_flag" => flag = false, + "manual_flag" => { + flag = false; + manual_flag = true; + }, _ => { return syn::Error::new(segments[0].ident.span(), "unknown macro param").to_compile_error().into(); } @@ -368,6 +373,29 @@ pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream { Err(err) => return err }; + if manual_flag { + let mut found_flag = false; + for attr in attrs.iter() { + match attr { + AttrType::Array(_, ident, _, _) => { + if ident.to_string() == "flag" { + found_flag = true; + break; + } + }, + AttrType::Value(_, ident, _) => { + if ident.to_string() == "flag" { + found_flag = true; + break; + } + } + } + } + if !found_flag { + return syn::Error::new(pkt_struct.ident.span(), "struct must have flag if manual_flag is set").to_compile_error().into(); + } + } + let struct_def = generate_struct_def(pkt_struct.ident.clone(), &attrs); let psopacket_impl = generate_psopacket_impl(cmd, pkt_struct.ident.clone(), &attrs, flag); let debug_impl = generate_debug_impl(pkt_struct.ident.clone(), &attrs);