From b692b8b4170634aa7f273d39ad28e54233d7d23f Mon Sep 17 00:00:00 2001 From: jake Date: Sat, 9 Nov 2019 23:06:43 -0800 Subject: [PATCH] manual_flag should only check the first struct field --- psopacket/src/lib.rs | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/psopacket/src/lib.rs b/psopacket/src/lib.rs index 48f10c1..c89fb31 100644 --- a/psopacket/src/lib.rs +++ b/psopacket/src/lib.rs @@ -374,26 +374,18 @@ pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream { }; 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; - } + match &attrs[0] { + AttrType::Array(_, ident, _, _) => { + if ident.to_string() != "flag" { + return syn::Error::new(pkt_struct.ident.span(), "struct must have flag as the first field if manual_flag is set").to_compile_error().into(); + } + }, + AttrType::Value(_, ident, _) => { + if ident.to_string() != "flag" { + return syn::Error::new(pkt_struct.ident.span(), "struct must have flag as the first field if manual_flag is set").to_compile_error().into(); } } } - 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);