Browse Source

manual_flag should only check the first struct field

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

18
psopacket/src/lib.rs

@ -374,27 +374,19 @@ pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream {
};
if manual_flag {
let mut found_flag = false;
for attr in attrs.iter() {
match attr {
match &attrs[0] {
AttrType::Array(_, ident, _, _) => {
if ident.to_string() == "flag" {
found_flag = true;
break;
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" {
found_flag = true;
break;
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 psopacket_impl = generate_psopacket_impl(cmd, pkt_struct.ident.clone(), &attrs, flag);

Loading…
Cancel
Save