From 595fad3ba0bd7c011256ef472ef1e1aa07dbed36 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sat, 26 Nov 2022 00:48:36 +0000 Subject: [PATCH] rename MultipartCollect trait --- actix-multipart-derive/src/lib.rs | 28 ++++++++++++++-------------- actix-multipart/src/form/mod.rs | 10 +++++----- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/actix-multipart-derive/src/lib.rs b/actix-multipart-derive/src/lib.rs index 5f0b9245f..937d47bde 100644 --- a/actix-multipart-derive/src/lib.rs +++ b/actix-multipart-derive/src/lib.rs @@ -49,7 +49,7 @@ struct ParsedField<'t> { ty: &'t Type, } -/// Implements the `MultipartFormTrait` for a struct so that it can be used with the `MultipartForm` +/// Implements `MultipartCollect` for a struct so that it can be used with the `MultipartForm` /// extractor. /// /// # Basic Use @@ -241,7 +241,18 @@ pub fn impl_multipart_form(input: proc_macro::TokenStream) -> proc_macro::TokenS DuplicateField::Replace => quote!(::actix_multipart::form::DuplicateField::Replace), }; - // read_field() implementation + // limit() implementation + let mut limit_impl = quote!(); + for field in &parsed { + let name = &field.serialization_name; + if let Some(value) = field.limit { + limit_impl.extend(quote!( + #name => ::std::option::Option::Some(#value), + )); + } + } + + // handle_field() implementation let mut read_field_impl = quote!(); for field in &parsed { let name = &field.serialization_name; @@ -254,17 +265,6 @@ pub fn impl_multipart_form(input: proc_macro::TokenStream) -> proc_macro::TokenS )); } - // limit() implementation - let mut limit_impl = quote!(); - for field in &parsed { - let name = &field.serialization_name; - if let Some(value) = field.limit { - limit_impl.extend(quote!( - #name => ::std::option::Option::Some(#value), - )); - } - } - // from_state() implementation let mut from_state_impl = quote!(); for field in &parsed { @@ -277,7 +277,7 @@ pub fn impl_multipart_form(input: proc_macro::TokenStream) -> proc_macro::TokenS } let gen = quote! { - impl ::actix_multipart::form::MultipartFormTrait for #name { + impl ::actix_multipart::form::MultipartCollect for #name { fn limit(field_name: &str) -> ::std::option::Option { match field_name { #limit_impl diff --git a/actix-multipart/src/form/mod.rs b/actix-multipart/src/form/mod.rs index 2052042cb..c94a457f1 100644 --- a/actix-multipart/src/form/mod.rs +++ b/actix-multipart/src/form/mod.rs @@ -184,7 +184,7 @@ where /// Trait that allows a type to be used in the [`struct@MultipartForm`] extractor. You should use /// the [`macro@MultipartForm`] to implement this for your struct. -pub trait MultipartFormTrait: Sized { +pub trait MultipartCollect: Sized { /// An optional limit in bytes to be applied a given field name. Note this limit will be shared /// across all fields sharing the same name. fn limit(field_name: &str) -> Option; @@ -270,14 +270,14 @@ impl Limits { /// Typed `multipart/form-data` extractor. /// /// To extract typed data from a multipart stream, the inner type `T` must implement the -/// [`MultipartFormTrait`] trait, you should use the [`macro@MultipartForm`] macro to derive this +/// [`MultipartCollect`] trait, you should use the [`macro@MultipartForm`] macro to derive this /// for your struct. /// /// Use [`MultipartFormConfig`] to configure extraction options. #[derive(Deref, DerefMut)] -pub struct MultipartForm(pub T); +pub struct MultipartForm(pub T); -impl MultipartForm { +impl MultipartForm { /// Unwrap into inner `T` value. pub fn into_inner(self) -> T { self.0 @@ -286,7 +286,7 @@ impl MultipartForm { impl FromRequest for MultipartForm where - T: MultipartFormTrait, + T: MultipartCollect, { type Error = Error; type Future = LocalBoxFuture<'static, Result>;