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

Skip to content

Commit a9db889

Browse files
committed
Update to syn 2.0, darling 0.20 (#386)
* Update to syn 2.0, darling 0.20 - Change `type` for enums into `id_type`, as this is no longer accepted through the syn parser library * Update to rstest 0.18
1 parent ccd5b0e commit a9db889

29 files changed

Lines changed: 108 additions & 110 deletions

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ This also disallows using tuples for storing the id:
111111
old:
112112
```rust
113113
#[derive(PartialEq, Debug, DekuRead, DekuWrite)]
114-
#[deku(type = "u8")]
114+
#[deku(id_type = "u8")]
115115
enum DekuTest {
116116
#[deku(id_pat = "_")]
117117
VariantC((u8, u8)),
@@ -121,7 +121,7 @@ enum DekuTest {
121121
new:
122122
```rust
123123
#[derive(PartialEq, Debug, DekuRead, DekuWrite)]
124-
#[deku(type = "u8")]
124+
#[deku(id_type = "u8")]
125125
enum DekuTest {
126126
#[deku(id_pat = "_")]
127127
VariantC {

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ log = { version = "0.4.17", optional = true }
3232
no_std_io = { version = "0.5.0", default-features = false, features = ["alloc"] }
3333

3434
[dev-dependencies]
35-
rstest = "0.16.0"
35+
rstest = "0.18.0"
3636
hexlit = "0.5.5"
3737
criterion = "0.4.0"
3838
alloc_counter = "0.0.4"

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ logging = []
1818

1919
[dependencies]
2020
quote = "1.0"
21-
syn = "1.0"
21+
syn = "2.0"
2222
# extra-traits gives us Debug
2323
# syn = {version = "1.0", features = ["extra-traits"]}
2424
proc-macro2 = "1.0"
25-
darling = "0.14"
25+
darling = "0.20"
2626
proc-macro-crate = { version = "1.3.0", optional = true }
2727

2828
[dev-dependencies]
29-
rstest = "0.16"
29+
rstest = "0.18"

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;
@@ -208,7 +207,10 @@ impl DekuData {
208207
ast::Data::Struct(_) => {
209208
// Validate id_* attributes are being used on an enum
210209
if data.id_type.is_some() {
211-
Err(cerror(data.id_type.span(), "`type` only supported on enum"))
210+
Err(cerror(
211+
data.id_type.span(),
212+
"`id_type` only supported on enum",
213+
))
212214
} else if data.id.is_some() {
213215
Err(cerror(data.id.span(), "`id` only supported on enum"))
214216
} else if data.bytes.is_some() {
@@ -220,19 +222,19 @@ impl DekuData {
220222
}
221223
}
222224
ast::Data::Enum(_) => {
223-
// Validate `type` or `id` is specified
225+
// Validate `id_type` or `id` is specified
224226
if data.id_type.is_none() && data.id.is_none() {
225227
return Err(cerror(
226228
data.ident.span(),
227-
"`type` or `id` must be specified on enum",
229+
"`id_type` or `id` must be specified on enum",
228230
));
229231
}
230232

231-
// Validate either `type` or `id` is specified
233+
// Validate either `id_type` or `id` is specified
232234
if data.id_type.is_some() && data.id.is_some() {
233235
return Err(cerror(
234236
data.ident.span(),
235-
"conflicting: both `type` and `id` specified on enum",
237+
"conflicting: both `id_type` and `id` specified on enum",
236238
));
237239
}
238240

@@ -654,11 +656,7 @@ struct DekuReceiver {
654656
id: Option<Id>,
655657

656658
/// enum only: type of the enum `id`
657-
#[darling(
658-
rename = "type",
659-
default = "default_res_opt",
660-
map = "map_litstr_as_tokenstream"
661-
)]
659+
#[darling(default = "default_res_opt", map = "map_litstr_as_tokenstream")]
662660
id_type: Result<Option<TokenStream>, ReplacementError>,
663661

664662
/// enum only: bit size of the enum `id`
@@ -898,7 +896,7 @@ pub fn proc_deku_write(input: proc_macro::TokenStream) -> proc_macro::TokenStrea
898896
}
899897

900898
fn is_not_deku(attr: &syn::Attribute) -> bool {
901-
attr.path
899+
attr.path()
902900
.get_ident()
903901
.map(|ident| ident != "deku" && ident != "deku_derive")
904902
.unwrap_or(true)
@@ -962,8 +960,8 @@ pub fn deku_derive(
962960
item: proc_macro::TokenStream,
963961
) -> proc_macro::TokenStream {
964962
// Parse `deku_derive` attribute
965-
let attr_args = syn::parse_macro_input!(attr as AttributeArgs);
966-
let args = match DekuDerive::from_list(&attr_args) {
963+
let nested_meta = darling::ast::NestedMeta::parse_meta_list(attr.into()).unwrap();
964+
let args = match DekuDerive::from_list(&nested_meta) {
967965
Ok(v) => v,
968966
Err(e) => {
969967
return proc_macro::TokenStream::from(e.write_errors());
@@ -1062,9 +1060,9 @@ mod tests {
10621060
}"#),
10631061
10641062
// Valid Enum
1065-
case::enum_empty(r#"#[deku(type = "u8")] enum Test {}"#),
1063+
case::enum_empty(r#"#[deku(id_type = "u8")] enum Test {}"#),
10661064
case::enum_all(r#"
1067-
#[deku(type = "u8")]
1065+
#[deku(id_type = "u8")]
10681066
enum Test {
10691067
#[deku(id = "1")]
10701068
A,

examples/enums.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use hexlit::hex;
66
const THREE: u8 = 3;
77

88
#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
9-
#[deku(type = "u8")]
9+
#[deku(id_type = "u8")]
1010
enum DekuTest {
1111
#[deku(id = 0)]
1212
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
@@ -1057,7 +1057,7 @@ Example:
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
#[deku(id = 0x01)]
10631063
VariantA(u8),
@@ -1095,7 +1095,7 @@ Example discriminant
10951095
# use std::io::Cursor;
10961096
# use std::convert::{TryInto, TryFrom};
10971097
# #[derive(PartialEq, Debug, DekuRead, DekuWrite)]
1098-
#[deku(type = "u8")]
1098+
#[deku(id_type = "u8")]
10991099
enum DekuTest {
11001100
VariantA = 0x01,
11011101
VariantB,
@@ -1137,7 +1137,7 @@ Example:
11371137
# use std::io::Cursor;
11381138
# use std::convert::{TryInto, TryFrom};
11391139
# #[derive(PartialEq, Debug, DekuRead, DekuWrite)]
1140-
#[deku(type = "u8")]
1140+
#[deku(id_type = "u8")]
11411141
enum DekuTest {
11421142
#[deku(id = 0x01)]
11431143
VariantA(u8),
@@ -1189,7 +1189,7 @@ Example:
11891189
# use std::io::Cursor;
11901190
# use std::convert::{TryInto, TryFrom};
11911191
# #[derive(PartialEq, Debug, DekuRead, DekuWrite)]
1192-
#[deku(type = "u8", bits = 4)]
1192+
#[deku(id_type = "u8", bits = 4)]
11931193
enum DekuTest {
11941194
#[deku(id = 0b1001)]
11951195
VariantA( #[deku(bits = 4)] u8, u8),
@@ -1220,7 +1220,7 @@ Example:
12201220
# use deku::prelude::*;
12211221
# use std::convert::{TryInto, TryFrom};
12221222
# #[derive(PartialEq, Debug, DekuRead, DekuWrite)]
1223-
#[deku(type = "u32", bytes = 2)]
1223+
#[deku(id_type = "u32", bytes = 2)]
12241224
enum DekuTest {
12251225
#[deku(id = 0xBEEF)]
12261226
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),

0 commit comments

Comments
 (0)