rename MultipartCollect trait

This commit is contained in:
Rob Ede 2022-11-26 00:48:36 +00:00
parent b6e796da51
commit 595fad3ba0
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
2 changed files with 19 additions and 19 deletions

View File

@ -49,7 +49,7 @@ struct ParsedField<'t> {
ty: &'t Type, 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. /// extractor.
/// ///
/// # Basic Use /// # 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), 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!(); let mut read_field_impl = quote!();
for field in &parsed { for field in &parsed {
let name = &field.serialization_name; 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 // from_state() implementation
let mut from_state_impl = quote!(); let mut from_state_impl = quote!();
for field in &parsed { for field in &parsed {
@ -277,7 +277,7 @@ pub fn impl_multipart_form(input: proc_macro::TokenStream) -> proc_macro::TokenS
} }
let gen = quote! { 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<usize> { fn limit(field_name: &str) -> ::std::option::Option<usize> {
match field_name { match field_name {
#limit_impl #limit_impl

View File

@ -184,7 +184,7 @@ where
/// Trait that allows a type to be used in the [`struct@MultipartForm`] extractor. You should use /// 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. /// 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 /// 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. /// across all fields sharing the same name.
fn limit(field_name: &str) -> Option<usize>; fn limit(field_name: &str) -> Option<usize>;
@ -270,14 +270,14 @@ impl Limits {
/// Typed `multipart/form-data` extractor. /// Typed `multipart/form-data` extractor.
/// ///
/// To extract typed data from a multipart stream, the inner type `T` must implement the /// 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. /// for your struct.
/// ///
/// Use [`MultipartFormConfig`] to configure extraction options. /// Use [`MultipartFormConfig`] to configure extraction options.
#[derive(Deref, DerefMut)] #[derive(Deref, DerefMut)]
pub struct MultipartForm<T: MultipartFormTrait>(pub T); pub struct MultipartForm<T: MultipartCollect>(pub T);
impl<T: MultipartFormTrait> MultipartForm<T> { impl<T: MultipartCollect> MultipartForm<T> {
/// Unwrap into inner `T` value. /// Unwrap into inner `T` value.
pub fn into_inner(self) -> T { pub fn into_inner(self) -> T {
self.0 self.0
@ -286,7 +286,7 @@ impl<T: MultipartFormTrait> MultipartForm<T> {
impl<T> FromRequest for MultipartForm<T> impl<T> FromRequest for MultipartForm<T>
where where
T: MultipartFormTrait, T: MultipartCollect,
{ {
type Error = Error; type Error = Error;
type Future = LocalBoxFuture<'static, Result<Self, Self::Error>>; type Future = LocalBoxFuture<'static, Result<Self, Self::Error>>;