Skip to content

Commit

Permalink
Fix 'unused_qualifications' warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioBenitez committed May 4, 2024
1 parent b7c58fc commit f179206
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl<'r> Field<'r> {
#[cfg(feature = "json")]
#[cfg_attr(nightly, doc(cfg(feature = "json")))]
pub async fn json<T: DeserializeOwned>(self) -> crate::Result<T> {
serde_json::from_slice(&self.bytes().await?).map_err(crate::Error::DecodeJson)
serde_json::from_slice(&self.bytes().await?).map_err(Error::DecodeJson)
}

/// Get the full field data as text.
Expand Down Expand Up @@ -342,7 +342,7 @@ impl Stream for Field<'_> {
state.curr_field_size_counter += bytes.len() as u64;

if state.curr_field_size_counter > state.curr_field_size_limit {
return Poll::Ready(Some(Err(crate::Error::FieldSizeExceeded {
return Poll::Ready(Some(Err(Error::FieldSizeExceeded {
limit: state.curr_field_size_limit,
field_name: state.curr_field_name.clone(),
})));
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ pub fn parse_boundary<T: AsRef<str>>(content_type: T) -> Result<String> {
let m = content_type
.as_ref()
.parse::<mime::Mime>()
.map_err(crate::Error::DecodeContentType)?;
.map_err(Error::DecodeContentType)?;

if !(m.type_() == mime::MULTIPART && m.subtype() == mime::FORM_DATA) {
return Err(crate::Error::NoMultipart);
return Err(Error::NoMultipart);
}

m.get_param(mime::BOUNDARY)
.map(|name| name.as_str().to_owned())
.ok_or(crate::Error::NoBoundary)
.ok_or(Error::NoBoundary)
}

#[cfg(test)]
Expand Down
45 changes: 22 additions & 23 deletions src/multipart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl<'r> Multipart<'r> {
{
let stream = stream
.map_ok(|b| b.into())
.map_err(|err| crate::Error::StreamReadFailed(err.into()));
.map_err(|err| Error::StreamReadFailed(err.into()));

Multipart {
state: Arc::new(Mutex::new(MultipartState {
Expand Down Expand Up @@ -261,7 +261,7 @@ impl<'r> Multipart<'r> {
None => {
state.buffer.poll_stream(cx)?;
if state.buffer.eof {
return Poll::Ready(Err(crate::Error::IncompleteStream));
return Poll::Ready(Err(Error::IncompleteStream));
}
}
}
Expand All @@ -277,7 +277,7 @@ impl<'r> Multipart<'r> {
state.curr_field_size_counter += bytes.len() as u64;

if state.curr_field_size_counter > state.curr_field_size_limit {
return Poll::Ready(Err(crate::Error::FieldSizeExceeded {
return Poll::Ready(Err(Error::FieldSizeExceeded {
limit: state.curr_field_size_limit,
field_name: state.curr_field_name.clone(),
}));
Expand All @@ -303,7 +303,7 @@ impl<'r> Multipart<'r> {
Some(bytes) => bytes,
None => {
return if state.buffer.eof {
Poll::Ready(Err(crate::Error::IncompleteStream))
Poll::Ready(Err(Error::IncompleteStream))
} else {
Poll::Pending
};
Expand All @@ -313,7 +313,7 @@ impl<'r> Multipart<'r> {
if &boundary_bytes[..] == format!("{}{}", constants::BOUNDARY_EXT, boundary).as_bytes() {
state.stage = StreamingStage::DeterminingBoundaryType;
} else {
return Poll::Ready(Err(crate::Error::IncompleteStream));
return Poll::Ready(Err(Error::IncompleteStream));
}
}

Expand All @@ -323,7 +323,7 @@ impl<'r> Multipart<'r> {
Some(bytes) => bytes,
None => {
return if state.buffer.eof {
Poll::Ready(Err(crate::Error::IncompleteStream))
Poll::Ready(Err(Error::IncompleteStream))
} else {
Poll::Pending
};
Expand All @@ -341,7 +341,7 @@ impl<'r> Multipart<'r> {
if state.stage == StreamingStage::ReadingTransportPadding {
if !state.buffer.advance_past_transport_padding() {
return if state.buffer.eof {
Poll::Ready(Err(crate::Error::IncompleteStream))
Poll::Ready(Err(Error::IncompleteStream))
} else {
Poll::Pending
};
Expand All @@ -352,7 +352,7 @@ impl<'r> Multipart<'r> {
Some(bytes) => bytes,
None => {
return if state.buffer.eof {
Poll::Ready(Err(crate::Error::IncompleteStream))
Poll::Ready(Err(Error::IncompleteStream))
} else {
Poll::Pending
};
Expand All @@ -362,7 +362,7 @@ impl<'r> Multipart<'r> {
if &crlf_bytes[..] == constants::CRLF.as_bytes() {
state.stage = StreamingStage::ReadingFieldHeaders;
} else {
return Poll::Ready(Err(crate::Error::IncompleteStream));
return Poll::Ready(Err(Error::IncompleteStream));
}
}

Expand All @@ -371,7 +371,7 @@ impl<'r> Multipart<'r> {
Some(bytes) => bytes,
None => {
return if state.buffer.eof {
return Poll::Ready(Err(crate::Error::IncompleteStream));
return Poll::Ready(Err(Error::IncompleteStream));
} else {
Poll::Pending
};
Expand All @@ -380,20 +380,19 @@ impl<'r> Multipart<'r> {

let mut headers = [httparse::EMPTY_HEADER; constants::MAX_HEADERS];

let headers =
match httparse::parse_headers(&header_bytes, &mut headers).map_err(crate::Error::ReadHeaderFailed)? {
httparse::Status::Complete((_, raw_headers)) => {
match helpers::convert_raw_headers_to_header_map(raw_headers) {
Ok(headers) => headers,
Err(err) => {
return Poll::Ready(Err(err));
}
let headers = match httparse::parse_headers(&header_bytes, &mut headers).map_err(Error::ReadHeaderFailed)? {
httparse::Status::Complete((_, raw_headers)) => {
match helpers::convert_raw_headers_to_header_map(raw_headers) {
Ok(headers) => headers,
Err(err) => {
return Poll::Ready(Err(err));
}
}
httparse::Status::Partial => {
return Poll::Ready(Err(crate::Error::IncompleteHeaders));
}
};
}
httparse::Status::Partial => {
return Poll::Ready(Err(Error::IncompleteHeaders));
}
};

state.stage = StreamingStage::ReadingFieldData;

Expand All @@ -412,7 +411,7 @@ impl<'r> Multipart<'r> {

let field_name = content_disposition.field_name.as_deref();
if !state.constraints.is_it_allowed(field_name) {
return Poll::Ready(Err(crate::Error::UnknownField {
return Poll::Ready(Err(Error::UnknownField {
field_name: field_name.map(str::to_owned),
}));
}
Expand Down

0 comments on commit f179206

Please sign in to comment.