Browse Source

manual_flag should only check the first struct field

pull/3/head
jake 5 years ago
parent
commit
b692b8b417
  1. 26
      psopacket/src/lib.rs

26
psopacket/src/lib.rs

@ -374,26 +374,18 @@ pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream {
}; };
if manual_flag { 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); let struct_def = generate_struct_def(pkt_struct.ident.clone(), &attrs);

Loading…
Cancel
Save