Skip to content

Commit 1f64824

Browse files
committed
refactor: stricter rustc linting
1 parent b79d2da commit 1f64824

File tree

9 files changed

+34
-19
lines changed

9 files changed

+34
-19
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,17 @@
9999
//!
100100
//! For more examples, please visit [examples](https://github.com/rousan/multer-rs/tree/master/examples).
101101
102-
pub use bytes;
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))))]
103111

112+
pub use bytes;
104113
pub use constraints::Constraints;
105114
pub use error::Error;
106115
pub use field::Field;
@@ -133,7 +142,7 @@ pub type Result<T> = std::result::Result<T, Error>;
133142
/// # }
134143
/// # run();
135144
/// ```
136-
pub fn parse_boundary<T: AsRef<str>>(content_type: T) -> crate::Result<String> {
145+
pub fn parse_boundary<T: AsRef<str>>(content_type: T) -> Result<String> {
137146
let m = content_type
138147
.as_ref()
139148
.parse::<mime::Mime>()

src/multipart.rs

Lines changed: 5 additions & 12 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,
@@ -124,9 +125,6 @@ impl Multipart {
124125
///
125126
/// ```
126127
/// use multer::Multipart;
127-
/// use bytes::Bytes;
128-
/// use std::convert::Infallible;
129-
/// use futures::stream::once;
130128
///
131129
/// # async fn run() {
132130
/// let data = "--X-BOUNDARY\r\nContent-Disposition: form-data; name=\"my_text_field\"\r\n\r\nabcd\r\n--X-BOUNDARY--\r\n";
@@ -161,9 +159,6 @@ impl Multipart {
161159
///
162160
/// ```
163161
/// use multer::Multipart;
164-
/// use bytes::Bytes;
165-
/// use std::convert::Infallible;
166-
/// use futures::stream::once;
167162
///
168163
/// # async fn run() {
169164
/// let data = "--X-BOUNDARY\r\nContent-Disposition: form-data; name=\"my_text_field\"\r\n\r\nabcd\r\n--X-BOUNDARY--\r\n";
@@ -202,12 +197,10 @@ impl Multipart {
202197
/// # Examples
203198
///
204199
/// ```
200+
/// # #[cfg(feature = "reader")]
201+
/// # {
205202
/// use multer::Multipart;
206-
/// use bytes::Bytes;
207-
/// use std::convert::Infallible;
208-
/// use futures::stream::once;
209203
///
210-
/// # #[cfg(feature = "reader")]
211204
/// # async fn run() {
212205
/// let data = "--X-BOUNDARY\r\nContent-Disposition: form-data; name=\"my_text_field\"\r\n\r\nabcd\r\n--X-BOUNDARY--\r\n";
213206
/// let reader = data.as_bytes();
@@ -217,8 +210,8 @@ impl Multipart {
217210
/// println!("Index: {:?}, Content: {:?}", idx, field.text().await)
218211
/// }
219212
/// # }
220-
/// # #[cfg(feature = "reader")]
221213
/// # tokio::runtime::Runtime::new().unwrap().block_on(run());
214+
/// # }
222215
/// ```
223216
pub async fn next_field_with_idx(&mut self) -> crate::Result<Option<(usize, Field)>> {
224217
self.try_next().await.map(|f| f.map(|field| (field.index(), field)))
@@ -228,7 +221,7 @@ impl Multipart {
228221
impl Stream for Multipart {
229222
type Item = Result<Field, crate::Error>;
230223

231-
fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
224+
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
232225
let mut mutex_guard = match self.state.lock() {
233226
Ok(lock) => lock,
234227
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)