Skip to content

Commit 95b6a81

Browse files
committed
refactor: switch size parsing to bytesize crate
1 parent ab18efe commit 95b6a81

File tree

9 files changed

+31
-23
lines changed

9 files changed

+31
-23
lines changed

.cspell.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version: "0.2"
2+
words:
3+
- actix

Cargo.lock

+15-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actix-multipart-derive/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ all-features = true
1818
proc-macro = true
1919

2020
[dependencies]
21+
bytesize = "2"
2122
darling = "0.20"
22-
parse-size = "1"
2323
proc-macro2 = "1"
2424
quote = "1"
2525
syn = "2"
2626

2727
[dev-dependencies]
2828
actix-multipart = "0.7"
2929
actix-web = "4"
30-
rustversion = "1"
30+
rustversion-msrv = "0.100"
3131
trybuild = "1"
3232

3333
[lints]

actix-multipart-derive/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
use std::collections::HashSet;
1111

12+
use bytesize::ByteSize;
1213
use darling::{FromDeriveInput, FromField, FromMeta};
13-
use parse_size::parse_size;
1414
use proc_macro::TokenStream;
1515
use proc_macro2::Ident;
1616
use quote::quote;
@@ -103,7 +103,7 @@ struct ParsedField<'t> {
103103
/// # Field Limits
104104
///
105105
/// You can use the `#[multipart(limit = "<size>")]` attribute to set field level limits. The limit
106-
/// string is parsed using [parse_size].
106+
/// string is parsed using [`bytesize`].
107107
///
108108
/// Note: the form is also subject to the global limits configured using `MultipartFormConfig`.
109109
///
@@ -150,7 +150,7 @@ struct ParsedField<'t> {
150150
/// struct Form { }
151151
/// ```
152152
///
153-
/// [parse_size]: https://docs.rs/parse-size/1/parse_size
153+
/// [`bytesize`]: https://docs.rs/bytesize/2
154154
#[proc_macro_derive(MultipartForm, attributes(multipart))]
155155
pub fn impl_multipart_form(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
156156
let input: syn::DeriveInput = parse_macro_input!(input);
@@ -191,8 +191,8 @@ pub fn impl_multipart_form(input: proc_macro::TokenStream) -> proc_macro::TokenS
191191
let attrs = FieldAttrs::from_field(field).map_err(|err| err.write_errors())?;
192192
let serialization_name = attrs.rename.unwrap_or_else(|| rust_name.to_string());
193193

194-
let limit = match attrs.limit.map(|limit| match parse_size(&limit) {
195-
Ok(size) => Ok(usize::try_from(size).unwrap()),
194+
let limit = match attrs.limit.map(|limit| match limit.parse::<ByteSize>() {
195+
Ok(ByteSize(size)) => Ok(usize::try_from(size).unwrap()),
196196
Err(err) => Err(syn::Error::new(
197197
field.ident.as_ref().unwrap().span(),
198198
format!("Could not parse size limit `{}`: {}", limit, err),

actix-multipart-derive/tests/trybuild.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[rustversion::stable(1.72)] // MSRV
1+
#[rustversion_msrv::msrv]
22
#[test]
33
fn compile_macros() {
44
let t = trybuild::TestCases::new();

actix-multipart-derive/tests/trybuild/size-limit-parse-fail.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
error: Could not parse size limit `2 bytes`: invalid digit found in string
1+
error: Could not parse size limit `2 bytes`: couldn't parse "bytes" into a known SI unit, couldn't parse unit of "bytes"
22
--> tests/trybuild/size-limit-parse-fail.rs:6:5
33
|
44
6 | description: Text<String>,
55
| ^^^^^^^^^^^
66

7-
error: Could not parse size limit `2 megabytes`: invalid digit found in string
7+
error: Could not parse size limit `2 megabytes`: couldn't parse "megabytes" into a known SI unit, couldn't parse unit of "megabytes"
88
--> tests/trybuild/size-limit-parse-fail.rs:12:5
99
|
1010
12 | description: Text<String>,
1111
| ^^^^^^^^^^^
1212

13-
error: Could not parse size limit `four meters`: invalid digit found in string
13+
error: Could not parse size limit `four meters`: couldn't parse "four meters" into a ByteSize, cannot parse float from empty string
1414
--> tests/trybuild/size-limit-parse-fail.rs:18:5
1515
|
1616
18 | description: Text<String>,

actix-web-codegen/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ actix-web = "4"
3434

3535
futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] }
3636
trybuild = "1"
37-
rustversion = "1"
37+
rustversion-msrv = "0.100"
3838

3939
[lints]
4040
workspace = true

actix-web-codegen/tests/trybuild.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[rustversion::stable(1.72)] // MSRV
1+
#[rustversion_msrv::msrv]
22
#[test]
33
fn compile_macros() {
44
let t = trybuild::TestCases::new();

justfile

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ fmt:
1010
# Downgrade dependencies necessary to run MSRV checks/tests.
1111
[private]
1212
downgrade-for-msrv:
13-
cargo update -p=parse-size --precise=1.0.0 # next ver: 1.81.0
1413
cargo update -p=clap --precise=4.4.18 # next ver: 1.74.0
1514
cargo update -p=divan --precise=0.1.15 # next ver: 1.80.0
1615
cargo update -p=litemap --precise=0.7.4 # next ver: 1.81.0

0 commit comments

Comments
 (0)