Skip to content

Commit ac2d23a

Browse files
committed
refactor: stricter rustc linting
1 parent 706b1a1 commit ac2d23a

File tree

9 files changed

+34
-9
lines changed

9 files changed

+34
-9
lines changed

src/buffer.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::constants;
22
use bytes::{Bytes, BytesMut};
33
use futures::stream::Stream;
4+
use std::fmt;
45
use std::pin::Pin;
56
use std::task::{Context, Poll};
67

@@ -26,7 +27,7 @@ impl StreamBuffer {
2627
}
2728
}
2829

29-
pub fn poll_stream(&mut self, cx: &mut Context) -> Result<(), crate::Error> {
30+
pub fn poll_stream(&mut self, cx: &mut Context<'_>) -> Result<(), crate::Error> {
3031
if self.eof {
3132
return Ok(());
3233
}
@@ -151,3 +152,9 @@ impl StreamBuffer {
151152
self.buf.split_to(self.buf.len()).freeze()
152153
}
153154
}
155+
156+
impl fmt::Debug for StreamBuffer {
157+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
158+
f.debug_struct("StreamBuffer").finish()
159+
}
160+
}

src/constraints.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use crate::size_limit::SizeLimit;
4242
/// # }
4343
/// # tokio::runtime::Runtime::new().unwrap().block_on(run());
4444
/// ```
45+
#[derive(Debug)]
4546
pub struct Constraints {
4647
pub(crate) size_limit: SizeLimit,
4748
pub(crate) allowed_fields: Option<Vec<String>>,

src/content_disposition.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::constants;
22
use http::header::{self, HeaderMap};
33

4+
#[derive(Debug)]
45
pub(crate) struct ContentDisposition {
56
pub(crate) field_name: Option<String>,
67
pub(crate) file_name: Option<String>,

src/field.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ use std::task::{Context, Poll};
4848
/// then the parent [`Multipart`](./struct.Multipart.html) will never be able to yield the next field in the stream.
4949
/// The task waiting on the [`Multipart`](./struct.Multipart.html) will also never be notified, which, depending on the executor implementation,
5050
/// may cause a deadlock.
51+
#[derive(Debug)]
5152
pub struct Field {
5253
state: Arc<Mutex<MultipartState>>,
5354
headers: HeaderMap,
5455
done: bool,
5556
meta: FieldMeta,
5657
}
5758

59+
#[derive(Debug)]
5860
struct FieldMeta {
5961
content_disposition: ContentDisposition,
6062
content_type: Option<mime::Mime>,
@@ -228,7 +230,7 @@ impl Field {
228230
/// let stream = once(async move { Result::<Bytes, Infallible>::Ok(Bytes::from(data)) });
229231
/// let mut multipart = Multipart::new(stream, "X-BOUNDARY");
230232
///
231-
/// while let Some(mut field) = multipart.next_field().await.unwrap() {
233+
/// while let Some(field) = multipart.next_field().await.unwrap() {
232234
/// let content = field.text().await.unwrap();
233235
/// assert_eq!(content, "abcd");
234236
/// }
@@ -258,7 +260,7 @@ impl Field {
258260
/// let stream = once(async move { Result::<Bytes, Infallible>::Ok(Bytes::from(data)) });
259261
/// let mut multipart = Multipart::new(stream, "X-BOUNDARY");
260262
///
261-
/// while let Some(mut field) = multipart.next_field().await.unwrap() {
263+
/// while let Some(field) = multipart.next_field().await.unwrap() {
262264
/// let content = field.text_with_charset("utf-8").await.unwrap();
263265
/// assert_eq!(content, "abcd");
264266
/// }
@@ -314,7 +316,7 @@ impl Field {
314316
impl Stream for Field {
315317
type Item = Result<Bytes, crate::Error>;
316318

317-
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
319+
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
318320
if self.done {
319321
return Poll::Ready(None);
320322
}

src/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use http::header::{self, HeaderMap, HeaderName, HeaderValue};
22
use httparse::Header;
33
use std::convert::TryFrom;
44

5-
pub(crate) fn convert_raw_headers_to_header_map(raw_headers: &[Header]) -> crate::Result<HeaderMap> {
5+
pub(crate) fn convert_raw_headers_to_header_map(raw_headers: &[Header<'_>]) -> crate::Result<HeaderMap> {
66
let mut headers = HeaderMap::with_capacity(raw_headers.len());
77

88
for raw_header in raw_headers {

src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@
9999
//!
100100
//! For more examples, please visit [examples](https://github.com/rousan/multer-rs/tree/master/examples).
101101
102+
#![forbid(unsafe_code, future_incompatible)]
103+
#![warn(
104+
missing_debug_implementations,
105+
rust_2018_idioms,
106+
trivial_casts,
107+
unused_qualifications
108+
)]
109+
#![doc(test(attr(deny(rust_2018_idioms, warnings))))]
110+
#![doc(test(attr(allow(unused_extern_crates, unused_variables))))]
111+
102112
pub use constraints::Constraints;
103113
pub use error::Error;
104114
pub use field::Field;
@@ -131,7 +141,7 @@ pub type Result<T> = std::result::Result<T, Error>;
131141
/// # }
132142
/// # run();
133143
/// ```
134-
pub fn parse_boundary<T: AsRef<str>>(content_type: T) -> crate::Result<String> {
144+
pub fn parse_boundary<T: AsRef<str>>(content_type: T) -> Result<String> {
135145
let m = content_type
136146
.as_ref()
137147
.parse::<mime::Mime>()

src/multipart.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use tokio_util::codec::{BytesCodec, FramedRead};
4646
/// # }
4747
/// # tokio::runtime::Runtime::new().unwrap().block_on(run());
4848
/// ```
49+
#[derive(Debug)]
4950
pub struct Multipart {
5051
state: Arc<Mutex<MultipartState>>,
5152
constraints: Constraints,
@@ -202,12 +203,13 @@ impl Multipart {
202203
/// # Examples
203204
///
204205
/// ```
206+
/// # #[cfg(feature = "reader")]
207+
/// # {
205208
/// use multer::Multipart;
206209
/// use bytes::Bytes;
207210
/// use std::convert::Infallible;
208211
/// use futures::stream::once;
209212
///
210-
/// # #[cfg(feature = "reader")]
211213
/// # async fn run() {
212214
/// let data = "--X-BOUNDARY\r\nContent-Disposition: form-data; name=\"my_text_field\"\r\n\r\nabcd\r\n--X-BOUNDARY--\r\n";
213215
/// let reader = data.as_bytes();
@@ -217,8 +219,8 @@ impl Multipart {
217219
/// println!("Index: {:?}, Content: {:?}", idx, field.text().await)
218220
/// }
219221
/// # }
220-
/// # #[cfg(feature = "reader")]
221222
/// # tokio::runtime::Runtime::new().unwrap().block_on(run());
223+
/// # }
222224
/// ```
223225
pub async fn next_field_with_idx(&mut self) -> crate::Result<Option<(usize, Field)>> {
224226
self.try_next().await.map(|f| f.map(|field| (field.index(), field)))
@@ -228,7 +230,7 @@ impl Multipart {
228230
impl Stream for Multipart {
229231
type Item = Result<Field, crate::Error>;
230232

231-
fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
233+
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
232234
let mut mutex_guard = match self.state.lock() {
233235
Ok(lock) => lock,
234236
Err(err) => {

src/size_limit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::collections::HashMap;
44
/// Represents size limit of the stream to prevent DoS attacks.
55
///
66
/// Please refer [`Constraints`](./struct.Constraints.html) for more info.
7+
#[derive(Debug)]
78
pub struct SizeLimit {
89
pub(crate) whole_stream: u64,
910
pub(crate) per_field: u64,

src/state.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::buffer::StreamBuffer;
22
use std::task::Waker;
33

4+
#[derive(Debug)]
45
pub(crate) struct MultipartState {
56
pub(crate) buffer: StreamBuffer,
67
pub(crate) boundary: String,

0 commit comments

Comments
 (0)