Clippy nits
This commit is contained in:
parent
75d77bc08b
commit
38e6a890f3
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "actix-form-data"
|
||||
description = "Multipart Form Data for Actix Web"
|
||||
version = "0.6.0-beta.6"
|
||||
version = "0.6.0-beta.7"
|
||||
license = "GPL-3.0"
|
||||
authors = ["asonix <asonix@asonix.dog>"]
|
||||
repository = "https://git.asonix.dog/Aardwolf/actix-form-data.git"
|
||||
|
|
|
@ -26,9 +26,9 @@ use actix_web::{
|
|||
dev::{Payload, Service, ServiceRequest, Transform},
|
||||
FromRequest, HttpMessage, HttpRequest,
|
||||
};
|
||||
use futures_util::future::LocalBoxFuture;
|
||||
use std::{
|
||||
future::{ready, Future, Ready},
|
||||
pin::Pin,
|
||||
future::{ready, Ready},
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use tokio::sync::oneshot::{channel, Receiver};
|
||||
|
@ -45,9 +45,9 @@ pub struct MultipartMiddleware<S, T> {
|
|||
impl<T> FromRequest for Value<T>
|
||||
where
|
||||
T: 'static,
|
||||
{
|
||||
{
|
||||
type Error = Error;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<Self, Self::Error>>>>;
|
||||
type Future = LocalBoxFuture<'static, Result<Self, Self::Error>>;
|
||||
type Config = ();
|
||||
|
||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||
|
@ -88,7 +88,7 @@ where
|
|||
{
|
||||
type Response = S::Response;
|
||||
type Error = S::Error;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<S::Response, S::Error>>>>;
|
||||
type Future = LocalBoxFuture<'static, Result<S::Response, S::Error>>;
|
||||
|
||||
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
self.service.poll_ready(cx)
|
||||
|
|
64
src/types.rs
64
src/types.rs
|
@ -49,17 +49,10 @@ pub struct FileMeta<T = ()> {
|
|||
/// # let mut hm = HashMap::new();
|
||||
/// # hm.insert("field-name".to_owned(), Value::Int(32));
|
||||
/// # let value = Value::<()>::Map(hm);
|
||||
/// match value {
|
||||
/// Value::Map(mut hashmap) => {
|
||||
/// match hashmap.remove("field-name") {
|
||||
/// Some(value) => match value {
|
||||
/// Value::Int(integer) => println!("{}", integer),
|
||||
/// _ => (),
|
||||
/// }
|
||||
/// None => (),
|
||||
/// }
|
||||
/// if let Value::Map(mut hashmap) = value {
|
||||
/// if let Some(Value::Int(integer)) = hashmap.remove("field-name") {
|
||||
/// println!("{}", integer);
|
||||
/// }
|
||||
/// _ => (),
|
||||
/// }
|
||||
/// ```
|
||||
#[derive(Debug)]
|
||||
|
@ -186,7 +179,7 @@ impl<T> Clone for Field<T> {
|
|||
match self {
|
||||
Self::Array(a) => Self::Array(a.clone()),
|
||||
Self::Map(m) => Self::Map(m.clone()),
|
||||
Self::File(file_fn) => Self::File(Arc::clone(&file_fn)),
|
||||
Self::File(file_fn) => Self::File(Arc::clone(file_fn)),
|
||||
Self::Bytes => Self::Bytes,
|
||||
Self::Int => Self::Int,
|
||||
Self::Float => Self::Float,
|
||||
|
@ -386,15 +379,15 @@ pub struct Array<T = ()> {
|
|||
|
||||
impl<T> Clone for Array<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Array { inner: Box::new((*self.inner).clone()) }
|
||||
Array {
|
||||
inner: Box::new((*self.inner).clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> fmt::Debug for Array<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("Array")
|
||||
.field("inner", &self.inner)
|
||||
.finish()
|
||||
f.debug_struct("Array").field("inner", &self.inner).finish()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -408,11 +401,8 @@ impl<T> Array<T> {
|
|||
fn valid_field(&self, mut name: VecDeque<&NamePart>) -> Option<FieldTerminator<T>> {
|
||||
trace!("Checking {:?} and {:?}", self, name);
|
||||
match name.pop_front() {
|
||||
Some(name_part) => match name_part {
|
||||
NamePart::Array => self.inner.valid_field(name),
|
||||
_ => None,
|
||||
},
|
||||
None => None,
|
||||
Some(NamePart::Array) => self.inner.valid_field(name),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -424,15 +414,15 @@ pub struct Map<T = ()> {
|
|||
|
||||
impl<T> Clone for Map<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Map { inner: self.inner.clone() }
|
||||
Map {
|
||||
inner: self.inner.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> fmt::Debug for Map<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("Map")
|
||||
.field("inner", &self.inner)
|
||||
.finish()
|
||||
f.debug_struct("Map").field("inner", &self.inner).finish()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -473,15 +463,12 @@ impl<T> Map<T> {
|
|||
fn valid_field(&self, mut name: VecDeque<&NamePart>) -> Option<FieldTerminator<T>> {
|
||||
trace!("Checking {:?} and {:?}", self, name);
|
||||
match name.pop_front() {
|
||||
Some(name_part) => match name_part {
|
||||
NamePart::Map(part_name) => self
|
||||
.inner
|
||||
.iter()
|
||||
.find(|&&(ref item, _)| *item == *part_name)
|
||||
.and_then(|&(_, ref field)| field.valid_field(name)),
|
||||
_ => None,
|
||||
},
|
||||
None => None,
|
||||
Some(NamePart::Map(name_part)) => self
|
||||
.inner
|
||||
.iter()
|
||||
.find(|&&(ref item, _)| *item == *name_part)
|
||||
.and_then(|&(_, ref field)| field.valid_field(name)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -533,6 +520,12 @@ impl<T> Clone for Form<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Default for Form<T> {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Form<T> {
|
||||
/// Create a new form
|
||||
///
|
||||
|
@ -640,10 +633,7 @@ pub(crate) enum NamePart {
|
|||
|
||||
impl NamePart {
|
||||
pub fn is_map(&self) -> bool {
|
||||
match *self {
|
||||
NamePart::Map(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, NamePart::Map(_))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ fn parse_multipart_name(name: String) -> Result<Vec<NamePart>, Error> {
|
|||
})
|
||||
.fold(Ok(vec![]), |acc, part| match acc {
|
||||
Ok(mut v) => {
|
||||
if v.len() == 0 && !part.is_map() {
|
||||
if v.is_empty() && !part.is_map() {
|
||||
return Err(Error::ContentDisposition);
|
||||
}
|
||||
|
||||
|
@ -177,9 +177,7 @@ where
|
|||
let s = String::from_utf8(bytes.to_vec()).map_err(Error::ParseField)?;
|
||||
|
||||
match term {
|
||||
FieldTerminator::Bytes | FieldTerminator::File(_) => {
|
||||
return Err(Error::FieldType);
|
||||
}
|
||||
FieldTerminator::Bytes | FieldTerminator::File(_) => Err(Error::FieldType),
|
||||
FieldTerminator::Text => Ok(MultipartContent::Text(s)),
|
||||
FieldTerminator::Float => s
|
||||
.parse()
|
||||
|
@ -219,7 +217,10 @@ where
|
|||
}
|
||||
|
||||
/// Handle multipart streams from Actix Web
|
||||
pub async fn handle_multipart<T>(m: actix_multipart::Multipart, form: Form<T>) -> Result<Value<T>, Error>
|
||||
pub async fn handle_multipart<T>(
|
||||
m: actix_multipart::Multipart,
|
||||
form: Form<T>,
|
||||
) -> Result<Value<T>, Error>
|
||||
where
|
||||
T: 'static,
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue