Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea20cc5

Browse files
Merge 92c0b0f into a9df540
2 parents a9df540 + 92c0b0f commit ea20cc5

27 files changed

Lines changed: 116 additions & 117 deletions

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ This also disallows using tuples for storing the id:
109109
old:
110110
```rust
111111
#[derive(PartialEq, Debug, DekuRead, DekuWrite)]
112-
#[deku(type = "u8")]
112+
#[deku(id_type = "u8")]
113113
enum DekuTest {
114114
#[deku(id_pat = "_")]
115115
VariantC((u8, u8)),
@@ -119,7 +119,7 @@ enum DekuTest {
119119
new:
120120
```rust
121121
#[derive(PartialEq, Debug, DekuRead, DekuWrite)]
122-
#[deku(type = "u8")]
122+
#[deku(id_type = "u8")]
123123
enum DekuTest {
124124
#[deku(id_pat = "_")]
125125
VariantC {

benches/deku.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct DekuBytes {
2121
}
2222

2323
#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
24-
#[deku(type = "u8")]
24+
#[deku(id_type = "u8")]
2525
enum DekuEnum {
2626
#[deku(id = "0x01")]
2727
VariantA(u8),

deku-derive/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ logging = []
1717

1818
[dependencies]
1919
quote = "1.0"
20-
syn = "1.0"
20+
syn = "2.0"
2121
# extra-traits gives us Debug
2222
# syn = {version = "1.0", features = ["extra-traits"]}
2323
proc-macro2 = "1.0"
24-
darling = "0.14"
24+
darling = "0.20"
2525
proc-macro-crate = { version = "1.3.0", optional = true }
2626

2727
[dev-dependencies]

deku-derive/src/lib.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use proc_macro2::TokenStream;
1212
use quote::quote;
1313
use syn::punctuated::Punctuated;
1414
use syn::spanned::Spanned;
15-
use syn::AttributeArgs;
1615

1716
use crate::macros::deku_read::emit_deku_read;
1817
use crate::macros::deku_write::emit_deku_write;
@@ -205,7 +204,10 @@ impl DekuData {
205204
ast::Data::Struct(_) => {
206205
// Validate id_* attributes are being used on an enum
207206
if data.id_type.is_some() {
208-
Err(cerror(data.id_type.span(), "`type` only supported on enum"))
207+
Err(cerror(
208+
data.id_type.span(),
209+
"`id_type` only supported on enum",
210+
))
209211
} else if data.id.is_some() {
210212
Err(cerror(data.id.span(), "`id` only supported on enum"))
211213
} else if data.bytes.is_some() {
@@ -217,19 +219,19 @@ impl DekuData {
217219
}
218220
}
219221
ast::Data::Enum(_) => {
220-
// Validate `type` or `id` is specified
222+
// Validate `id_type` or `id` is specified
221223
if data.id_type.is_none() && data.id.is_none() {
222224
return Err(cerror(
223225
data.ident.span(),
224-
"`type` or `id` must be specified on enum",
226+
"`id_type` or `id` must be specified on enum",
225227
));
226228
}
227229

228-
// Validate either `type` or `id` is specified
230+
// Validate either `id_type` or `id` is specified
229231
if data.id_type.is_some() && data.id.is_some() {
230232
return Err(cerror(
231233
data.ident.span(),
232-
"conflicting: both `type` and `id` specified on enum",
234+
"conflicting: both `id_type` and `id` specified on enum",
233235
));
234236
}
235237

@@ -635,11 +637,7 @@ struct DekuReceiver {
635637
id: Option<Id>,
636638

637639
/// enum only: type of the enum `id`
638-
#[darling(
639-
rename = "type",
640-
default = "default_res_opt",
641-
map = "map_litstr_as_tokenstream"
642-
)]
640+
#[darling(default = "default_res_opt", map = "map_litstr_as_tokenstream")]
643641
id_type: Result<Option<TokenStream>, ReplacementError>,
644642

645643
/// enum only: bit size of the enum `id`
@@ -875,7 +873,7 @@ pub fn proc_deku_write(input: proc_macro::TokenStream) -> proc_macro::TokenStrea
875873
}
876874

877875
fn is_not_deku(attr: &syn::Attribute) -> bool {
878-
attr.path
876+
attr.path()
879877
.get_ident()
880878
.map(|ident| ident != "deku" && ident != "deku_derive")
881879
.unwrap_or(true)
@@ -939,8 +937,8 @@ pub fn deku_derive(
939937
item: proc_macro::TokenStream,
940938
) -> proc_macro::TokenStream {
941939
// Parse `deku_derive` attribute
942-
let attr_args = syn::parse_macro_input!(attr as AttributeArgs);
943-
let args = match DekuDerive::from_list(&attr_args) {
940+
let nested_meta = darling::ast::NestedMeta::parse_meta_list(attr.into()).unwrap();
941+
let args = match DekuDerive::from_list(&nested_meta) {
944942
Ok(v) => v,
945943
Err(e) => {
946944
return proc_macro::TokenStream::from(e.write_errors());
@@ -1039,9 +1037,9 @@ mod tests {
10391037
}"#),
10401038
10411039
// Valid Enum
1042-
case::enum_empty(r#"#[deku(type = "u8")] enum Test {}"#),
1040+
case::enum_empty(r#"#[deku(id_id_type = "u8")] enum Test {}"#),
10431041
case::enum_all(r#"
1044-
#[deku(type = "u8")]
1042+
#[deku(id_id_type = "u8")]
10451043
enum Test {
10461044
#[deku(id = "1")]
10471045
A,

examples/enums.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use deku::{prelude::*, reader::Reader};
44
use hexlit::hex;
55

66
#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
7-
#[deku(type = "u8")]
7+
#[deku(id_type = "u8")]
88
enum DekuTest {
99
#[deku(id = "0")]
1010
Var1,

examples/enums_catch_all.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use deku::prelude::*;
44
use hexlit::hex;
55

66
#[derive(Clone, Copy, PartialEq, Eq, Debug, DekuWrite, DekuRead)]
7-
#[deku(type = "u8")]
7+
#[deku(id_type = "u8")]
88
#[non_exhaustive]
99
#[repr(u8)]
1010
pub enum DekuTest {

src/attributes.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ Example:
10191019
# use std::io::Cursor;
10201020
# use std::convert::{TryInto, TryFrom};
10211021
# #[derive(PartialEq, Debug, DekuRead, DekuWrite)]
1022-
#[deku(type = "u8")]
1022+
#[deku(id_type = "u8")]
10231023
enum DekuTest {
10241024
#[deku(id = "0x01")]
10251025
VariantA(u8),
@@ -1057,7 +1057,7 @@ Example discriminant
10571057
# use std::io::Cursor;
10581058
# use std::convert::{TryInto, TryFrom};
10591059
# #[derive(PartialEq, Debug, DekuRead, DekuWrite)]
1060-
#[deku(type = "u8")]
1060+
#[deku(id_type = "u8")]
10611061
enum DekuTest {
10621062
VariantA = 0x01,
10631063
VariantB,
@@ -1099,7 +1099,7 @@ Example:
10991099
# use std::io::Cursor;
11001100
# use std::convert::{TryInto, TryFrom};
11011101
# #[derive(PartialEq, Debug, DekuRead, DekuWrite)]
1102-
#[deku(type = "u8")]
1102+
#[deku(id_type = "u8")]
11031103
enum DekuTest {
11041104
#[deku(id = "0x01")]
11051105
VariantA(u8),
@@ -1151,7 +1151,7 @@ Example:
11511151
# use std::io::Cursor;
11521152
# use std::convert::{TryInto, TryFrom};
11531153
# #[derive(PartialEq, Debug, DekuRead, DekuWrite)]
1154-
#[deku(type = "u8", bits = "4")]
1154+
#[deku(id_type = "u8", bits = "4")]
11551155
enum DekuTest {
11561156
#[deku(id = "0b1001")]
11571157
VariantA( #[deku(bits = "4")] u8, u8),
@@ -1182,7 +1182,7 @@ Example:
11821182
# use deku::prelude::*;
11831183
# use std::convert::{TryInto, TryFrom};
11841184
# #[derive(PartialEq, Debug, DekuRead, DekuWrite)]
1185-
#[deku(type = "u32", bytes = "2")]
1185+
#[deku(id_type = "u32", bytes = "2")]
11861186
enum DekuTest {
11871187
#[deku(id = "0xBEEF")]
11881188
VariantA(u8),

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Example:
174174
use deku::prelude::*;
175175
176176
#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
177-
#[deku(type = "u8")]
177+
#[deku(id_type = "u8")]
178178
enum DekuTest {
179179
#[deku(id = "0x01")]
180180
VariantA,

tests/test_alloc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ struct NestedStruct {
1414
}
1515

1616
#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
17-
#[deku(type = "u8", ctx = "_endian: Endian")]
17+
#[deku(id_type = "u8", ctx = "_endian: Endian")]
1818
enum NestedEnum {
1919
#[deku(id = "0x01")]
2020
VarA(u8),
2121
}
2222

2323
#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
24-
#[deku(type = "u32", bytes = "2", ctx = "_endian: Endian")]
24+
#[deku(id_type = "u32", bytes = "2", ctx = "_endian: Endian")]
2525
enum NestedEnum2 {
2626
#[deku(id = "0x01")]
2727
VarA(u8),

tests/test_attributes/test_ctx.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn test_ctx_struct() {
5151
#[test]
5252
fn test_top_level_ctx_enum() {
5353
#[derive(PartialEq, Debug, DekuRead, DekuWrite)]
54-
#[deku(type = "u8", ctx = "a: u8, b: u8")]
54+
#[deku(id_type = "u8", ctx = "a: u8, b: u8")]
5555
enum TopLevelCtxEnum {
5656
#[deku(id = "1")]
5757
VariantA(
@@ -80,7 +80,7 @@ fn test_top_level_ctx_enum() {
8080
#[test]
8181
fn test_top_level_ctx_enum_default() {
8282
#[derive(PartialEq, Debug, DekuRead, DekuWrite)]
83-
#[deku(type = "u8", ctx = "a: u8, b: u8", ctx_default = "1,2")]
83+
#[deku(id_type = "u8", ctx = "a: u8, b: u8", ctx_default = "1,2")]
8484
enum TopLevelCtxEnumDefault {
8585
#[deku(id = "1")]
8686
VariantA(
@@ -240,7 +240,7 @@ fn test_ctx_default_struct() {
240240
#[test]
241241
fn test_enum_endian_ctx() {
242242
#[derive(PartialEq, Debug, DekuRead, DekuWrite)]
243-
#[deku(type = "u32", endian = "endian", ctx = "endian: deku::ctx::Endian")]
243+
#[deku(id_type = "u32", endian = "endian", ctx = "endian: deku::ctx::Endian")]
244244
enum EnumTypeEndianCtx {
245245
#[deku(id = "0xDEADBEEF")]
246246
VarA(u8),

0 commit comments

Comments
 (0)