mirror of https://github.com/fafhrd91/actix-web
rename MultipartCollect trait
This commit is contained in:
parent
b6e796da51
commit
595fad3ba0
|
@ -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<usize> {
|
||||
match field_name {
|
||||
#limit_impl
|
||||
|
|
|
@ -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<usize>;
|
||||
|
@ -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<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.
|
||||
pub fn into_inner(self) -> T {
|
||||
self.0
|
||||
|
@ -286,7 +286,7 @@ impl<T: MultipartFormTrait> MultipartForm<T> {
|
|||
|
||||
impl<T> FromRequest for MultipartForm<T>
|
||||
where
|
||||
T: MultipartFormTrait,
|
||||
T: MultipartCollect,
|
||||
{
|
||||
type Error = Error;
|
||||
type Future = LocalBoxFuture<'static, Result<Self, Self::Error>>;
|
||||
|
|
Loading…
Reference in New Issue