Skip to content

Commit 2dba318

Browse files
committed
docs: Document limitation of BFieldCodec derive
Currently, ignoring fields in tuple structs is not supported. Please use a struct with named fields instead.
1 parent 0f69b07 commit 2dba318

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

bfieldcodec_derive/src/lib.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ use syn::Variant;
8080
/// #[derive(BFieldCodec)] // Currently not supported.
8181
/// enum Foo {} // Consider `struct Foo;` instead.
8282
/// ```
83+
///
84+
/// - Ignoring fields in tuple structs is currently not supported. Consider
85+
/// using a struct with named fields instead. Example:
86+
/// ```ignore
87+
/// #[derive(BFieldCodec)]
88+
/// struct Foo(#[bfield_codec(ignore)] u32);
89+
/// // ~~~~~~~~~~~~~~~~~~~~~~~
90+
/// // Currently not supported in tuple structs
91+
/// ```
8392
#[proc_macro_derive(BFieldCodec, attributes(bfield_codec))]
8493
pub fn bfieldcodec_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
8594
let ast = parse_macro_input!(input as DeriveInput);
@@ -210,11 +219,14 @@ impl BFieldCodecDeriveBuilder {
210219
.attrs
211220
.iter()
212221
.filter(|attr| attr.path().is_ident("bfield_codec"));
213-
let attribute = match relevant_attributes.clone().count() {
214-
0 => return false,
215-
1 => relevant_attributes.next().unwrap(),
216-
_ => panic!("field `{field_name}` must have at most 1 `bfield_codec` attribute"),
222+
223+
let Some(attribute) = relevant_attributes.next() else {
224+
return false;
217225
};
226+
if relevant_attributes.next().is_some() {
227+
panic!("field `{field_name}` must have at most 1 `bfield_codec` attribute");
228+
}
229+
218230
let parse_ignore = attribute.parse_nested_meta(|meta| match meta.path.get_ident() {
219231
Some(ident) if ident == "ignore" => Ok(()),
220232
Some(ident) => panic!("unknown identifier `{ident}` for field `{field_name}`"),

0 commit comments

Comments
 (0)