mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-03 08:34:07 +02:00
derive: dont try to parse attributes from outside the crate
This commit is contained in:
parent
0b781fa64a
commit
d6ea837c4e
4 changed files with 14 additions and 12 deletions
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "bitbuffer_derive"
|
||||
version = "0.11.0"
|
||||
version = "0.11.1"
|
||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||
edition = "2018"
|
||||
description = "Reading bit sequences from a byte slice"
|
||||
|
|
|
|||
|
|
@ -260,11 +260,9 @@ const BARE_ATTRS: &[&str] = &[
|
|||
|
||||
fn parse_attrs<T: Parse + Default + Merge>(attrs: &[Attribute]) -> Result<T> {
|
||||
let mut result = T::default();
|
||||
for attr in attrs {
|
||||
let parsed = if BARE_ATTRS
|
||||
.iter()
|
||||
.any(|name| attr.meta.path().is_ident(name))
|
||||
{
|
||||
for attr in attrs.iter() {
|
||||
let attr_path = attr.meta.path();
|
||||
let parsed = if BARE_ATTRS.iter().any(|name| attr_path.is_ident(name)) {
|
||||
let wrapped_meta = Meta::List(MetaList {
|
||||
path: parse_str("bitbuffer").unwrap(),
|
||||
delimiter: MacroDelimiter::Paren(Paren {
|
||||
|
|
@ -278,15 +276,17 @@ fn parse_attrs<T: Parse + Default + Merge>(attrs: &[Attribute]) -> Result<T> {
|
|||
bracket_token: attr.bracket_token,
|
||||
meta: wrapped_meta,
|
||||
};
|
||||
wrapped.parse_args()
|
||||
Some(wrapped.parse_args())
|
||||
} else if attr_path.is_ident("bitbuffer") {
|
||||
Some(attr.parse_args())
|
||||
} else {
|
||||
attr.parse_args()
|
||||
None
|
||||
};
|
||||
match parsed {
|
||||
Ok(parsed) => {
|
||||
Some(Ok(parsed)) => {
|
||||
result.merge(parsed);
|
||||
}
|
||||
Err(e) => {
|
||||
Some(Err(e)) => {
|
||||
// since we first parse our attrs as InputAttrs, and then the same attrs as either an Struct or EnumAttrs
|
||||
// when doing the first pass we expect a bunch of extra parameters
|
||||
let is_first_pass = type_name::<T>() == type_name::<InputAttrs>();
|
||||
|
|
@ -294,6 +294,7 @@ fn parse_attrs<T: Parse + Default + Merge>(attrs: &[Attribute]) -> Result<T> {
|
|||
return Err(e);
|
||||
}
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
Ok(result)
|
||||
|
|
|
|||
|
|
@ -244,10 +244,11 @@ fn test_read_struct3() {
|
|||
assert_eq!(None, bit_size_of::<TestStruct3<LittleEndian>>());
|
||||
}
|
||||
|
||||
#[derive(BitRead, PartialEq, Debug)]
|
||||
#[derive(BitRead, PartialEq, Debug, Default)]
|
||||
#[discriminant_bits = 2]
|
||||
enum TestEnumRest {
|
||||
Foo,
|
||||
#[default]
|
||||
Bar,
|
||||
#[discriminant = "_"]
|
||||
Asd,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue