Skip to content

Commit 7a0c2a6

Browse files
authored
Merge pull request #38 from meilisearch/update-dependencies
Update dependencies
2 parents 32bb33a + a3fc57c commit 7a0c2a6

File tree

3 files changed

+19
-39
lines changed

3 files changed

+19
-39
lines changed

derive/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ proc-macro = true
1313
[dependencies]
1414
proc-macro2 = "1.0"
1515
quote = "1.0.2"
16-
syn = { version = "1.0", features=["extra-traits", "parsing"]}
17-
convert_case = "0.5.0"
16+
syn = { version = "2.0", features=["extra-traits", "parsing"]}
17+
convert_case = "0.6.0"
1818

1919
[package.metadata.docs.rs]
2020
targets = ["x86_64-unknown-linux-gnu"]

derive/src/attribute_parser.rs

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@ use proc_macro2::{Ident, Span};
22
use syn::{
33
parenthesized,
44
parse::{ParseBuffer, ParseStream},
5-
parse2, Attribute, DeriveInput, Expr, ExprPath, GenericParam, LitStr, Token, WherePredicate,
5+
Attribute, DeriveInput, Expr, ExprPath, GenericParam, LitStr, Token, WherePredicate,
66
};
77

8-
// pub struct MapFieldAttribute {
9-
// // from_ty: Option<syn::Type>,
10-
// map_func: syn::ExprPath,
11-
// }
12-
138
/// Attributes that are applied to fields.
149
#[derive(Default, Debug, Clone)]
1510
pub struct FieldAttributesInfo {
@@ -154,12 +149,7 @@ fn parse_rename(input: &ParseBuffer) -> Result<LitStr, syn::Error> {
154149
impl syn::parse::Parse for FieldAttributesInfo {
155150
fn parse(input: ParseStream) -> syn::Result<Self> {
156151
let mut this = FieldAttributesInfo::default();
157-
// parse starting right after #[deserr .... ]
158-
// so first get the content inside the parentheses
159152

160-
let content;
161-
let _ = parenthesized!(content in input);
162-
let input = content;
163153
// consumed input: #[deserr( .... )]
164154

165155
loop {
@@ -168,7 +158,7 @@ impl syn::parse::Parse for FieldAttributesInfo {
168158
// consumed input: #[deserr( ... attr_name ... )]
169159
match attr_name.to_string().as_str() {
170160
"rename" => {
171-
other.rename = Some(parse_rename(&input)?);
161+
other.rename = Some(parse_rename(input)?);
172162
}
173163
"default" => {
174164
if input.peek(Token![=]) {
@@ -201,12 +191,12 @@ impl syn::parse::Parse for FieldAttributesInfo {
201191
other.map = Some(func);
202192
}
203193
"from" => {
204-
let from_attr = parse_attribute_from(attr_name.span(), &input)?;
194+
let from_attr = parse_attribute_from(attr_name.span(), input)?;
205195
// #[deserr( .. from(from_ty) = function::path::<_>)]
206196
other.from = Some(from_attr);
207197
}
208198
"try_from" => {
209-
let try_from_attr = parse_attribute_try_from(attr_name.span(), &input)?;
199+
let try_from_attr = parse_attribute_try_from(attr_name.span(), input)?;
210200
// #[deserr( .. try_from(from_ty) = function::path::<_> -> to_ty )]
211201
other.try_from = Some(try_from_attr);
212202
}
@@ -243,11 +233,11 @@ pub fn read_deserr_field_attributes(
243233
) -> Result<FieldAttributesInfo, syn::Error> {
244234
let mut this = FieldAttributesInfo::default();
245235
for attribute in attributes {
246-
if let Some(ident) = attribute.path.get_ident() {
236+
if let Some(ident) = attribute.path().get_ident() {
247237
if ident != "deserr" {
248238
continue;
249239
}
250-
let other = parse2::<FieldAttributesInfo>(attribute.tokens.clone())?;
240+
let other: FieldAttributesInfo = attribute.parse_args()?;
251241
this.merge(other)?;
252242
} else {
253243
continue;
@@ -519,20 +509,15 @@ fn parse_attribute_try_from(
519509
impl syn::parse::Parse for ContainerAttributesInfo {
520510
fn parse(input: ParseStream) -> syn::Result<Self> {
521511
let mut this = ContainerAttributesInfo::default();
522-
// parse starting right after #[deserr .... ]
523-
// so first get the content inside the parentheses
524512

525-
let content;
526-
let _ = parenthesized!(content in input);
527-
let input = content;
528513
// consumed input: #[deserr( .... )]
529514

530515
loop {
531516
let attr_name = input.parse::<Ident>()?;
532517
// consumed input: #[deserr( ... attr_name ... )]
533518
match attr_name.to_string().as_str() {
534519
"rename_all" => {
535-
let rename_all = parse_rename_all(&input)?;
520+
let rename_all = parse_rename_all(input)?;
536521
this.rename_all = Some(rename_all);
537522
this.rename_all_span = Some(attr_name.span());
538523
}
@@ -561,20 +546,20 @@ impl syn::parse::Parse for ContainerAttributesInfo {
561546
this.deny_unknown_fields_span = Some(attr_name.span());
562547
}
563548
"from" => {
564-
let from_attr = parse_attribute_from(attr_name.span(), &input)?;
549+
let from_attr = parse_attribute_from(attr_name.span(), input)?;
565550
// #[deserr( .. from(from_ty) = function::path::<_>)]
566551
this.from = Some(from_attr);
567552
}
568553
"try_from" => {
569-
let try_from_attr = parse_attribute_try_from(attr_name.span(), &input)?;
554+
let try_from_attr = parse_attribute_try_from(attr_name.span(), input)?;
570555
// #[deserr( .. try_from(from_ty) = function::path::<_> -> to_ty )]
571556
this.try_from = Some(try_from_attr);
572557
}
573558
"validate" => {
574559
// #[deserr( ... validate .. )]
575560
let _eq = input.parse::<Token![=]>()?;
576561
// #[deserr( ... validate = .. )]
577-
let validate_func = parse_function_returning_error(&input)?;
562+
let validate_func = parse_function_returning_error(input)?;
578563
// #[deserr( ... validate = some::func<T> )]
579564
this.validate = Some(validate_func);
580565
}
@@ -655,11 +640,11 @@ pub fn read_deserr_container_attributes(
655640
) -> Result<ContainerAttributesInfo, syn::Error> {
656641
let mut this = ContainerAttributesInfo::default();
657642
for attribute in attributes {
658-
if let Some(ident) = attribute.path.get_ident() {
643+
if let Some(ident) = attribute.path().get_ident() {
659644
if ident != "deserr" {
660645
continue;
661646
}
662-
let other = parse2::<ContainerAttributesInfo>(attribute.tokens.clone())?;
647+
let other: ContainerAttributesInfo = attribute.parse_args()?;
663648
this.merge(other)?;
664649
} else {
665650
continue;
@@ -726,23 +711,18 @@ impl VariantAttributesInfo {
726711
impl syn::parse::Parse for VariantAttributesInfo {
727712
fn parse(input: ParseStream) -> syn::Result<Self> {
728713
let mut this = VariantAttributesInfo::default();
729-
// parse starting right after #[deserr .... ]
730-
// so first get the content inside the parentheses
731714

732-
let content;
733-
let _ = parenthesized!(content in input);
734-
let input = content;
735715
// consumed input: #[deserr( .... )]
736716

737717
loop {
738718
let attr_name = input.parse::<Ident>()?;
739719
// consumed input: #[deserr( ... attr_name ... )]
740720
match attr_name.to_string().as_str() {
741721
"rename" => {
742-
this.rename = Some(parse_rename(&input)?);
722+
this.rename = Some(parse_rename(input)?);
743723
}
744724
"rename_all" => {
745-
this.rename_all = Some(parse_rename_all(&input)?);
725+
this.rename_all = Some(parse_rename_all(input)?);
746726
this.rename_all_span = Some(attr_name.span());
747727
}
748728
_ => {
@@ -774,11 +754,11 @@ pub fn read_deserr_variant_attributes(
774754
) -> Result<VariantAttributesInfo, syn::Error> {
775755
let mut this = VariantAttributesInfo::default();
776756
for attribute in attributes {
777-
if let Some(ident) = attribute.path.get_ident() {
757+
if let Some(ident) = attribute.path().get_ident() {
778758
if ident != "deserr" {
779759
continue;
780760
}
781-
let other = parse2::<VariantAttributesInfo>(attribute.tokens.clone())?;
761+
let other: VariantAttributesInfo = attribute.parse_args()?;
782762
this.merge(other)?;
783763
} else {
784764
continue;

examples/actix_web_server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ edition = "2021"
99
actix-http = { version = "3.2.2", default-features = false, features = ["compress-brotli", "compress-gzip", "rustls"] }
1010
actix-web = { version = "4.2.1", default-features = false, features = ["macros", "compress-brotli", "compress-gzip", "cookies", "rustls"] }
1111
anyhow = "1.0.68"
12-
deserr = { path = "../../" }
12+
deserr = { path = "../../", features = ["actix-web"] }
1313
env_logger = "0.10.0"
1414
futures = "0.3.25"
1515
futures-util = "0.3.25"

0 commit comments

Comments
 (0)