chore: address clippy lints

This commit is contained in:
Rob Ede 2023-08-28 23:06:34 +01:00
parent cbf5e948db
commit 5de1c9de75
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
8 changed files with 26 additions and 19 deletions

View File

@ -66,6 +66,7 @@ type PathFilter = dyn Fn(&Path, &RequestHead) -> bool;
#[cfg(test)]
mod tests {
use std::{
fmt::Write as _,
fs::{self},
ops::Add,
time::{Duration, SystemTime},
@ -848,8 +849,10 @@ mod tests {
let filename_encoded = filename
.as_bytes()
.iter()
.map(|c| format!("%{:02X}", c))
.collect::<String>();
.fold(String::new(), |mut buf, c| {
write!(&mut buf, "%{:02X}", c).unwrap();
buf
});
std::fs::File::create(tmpdir.path().join(filename)).unwrap();
let srv = test::init_service(App::new().service(Files::new("", tmpdir.path()))).await;

View File

@ -117,6 +117,7 @@ impl PayloadSender {
}
}
#[allow(clippy::needless_pass_by_ref_mut)]
#[inline]
pub fn need_read(&self, cx: &mut Context<'_>) -> PayloadStatus {
// we check need_read only if Payload (other side) is alive,
@ -174,7 +175,7 @@ impl Inner {
/// Register future waiting data from payload.
/// Waker would be used in `Inner::wake`
fn register(&mut self, cx: &mut Context<'_>) {
fn register(&mut self, cx: &Context<'_>) {
if self
.task
.as_ref()
@ -186,7 +187,7 @@ impl Inner {
// Register future feeding data to payload.
/// Waker would be used in `Inner::wake_io`
fn register_io(&mut self, cx: &mut Context<'_>) {
fn register_io(&mut self, cx: &Context<'_>) {
if self
.io_task
.as_ref()
@ -221,7 +222,7 @@ impl Inner {
fn poll_next(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
cx: &Context<'_>,
) -> Poll<Option<Result<Bytes, PayloadError>>> {
if let Some(data) = self.items.pop_front() {
self.len -= data.len();

View File

@ -252,7 +252,7 @@ impl InnerMultipart {
fn poll(
&mut self,
safety: &Safety,
cx: &mut Context<'_>,
cx: &Context<'_>,
) -> Poll<Option<Result<Field, MultipartError>>> {
if self.state == InnerState::Eof {
Poll::Ready(None)
@ -740,7 +740,7 @@ impl Safety {
self.clean.get()
}
fn clone(&self, cx: &mut Context<'_>) -> Safety {
fn clone(&self, cx: &Context<'_>) -> Safety {
let payload = Rc::clone(&self.payload);
let s = Safety {
task: LocalWaker::new(),

View File

@ -1,6 +1,6 @@
#![allow(clippy::uninlined_format_args)]
use std::borrow::Cow;
use std::{borrow::Cow, fmt::Write as _};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
@ -8,9 +8,10 @@ fn compare_quoters(c: &mut Criterion) {
let mut group = c.benchmark_group("Compare Quoters");
let quoter = actix_router::Quoter::new(b"", b"");
let path_quoted = (0..=0x7f)
.map(|c| format!("%{:02X}", c))
.collect::<String>();
let path_quoted = (0..=0x7f).fold(String::new(), |mut buf, c| {
write!(&mut buf, "%{:02X}", c).unwrap();
buf
});
let path_unquoted = ('\u{00}'..='\u{7f}').collect::<String>();
group.bench_function("quoter_unquoted", |b| {

View File

@ -62,6 +62,8 @@ impl ResourcePath for Url {
#[cfg(test)]
mod tests {
use std::fmt::Write as _;
use http::Uri;
use super::*;
@ -78,7 +80,11 @@ mod tests {
}
fn percent_encode(data: &[u8]) -> String {
data.iter().map(|c| format!("%{:02X}", c)).collect()
data.iter()
.fold(String::with_capacity(data.len() * 3), |mut buf, c| {
write!(&mut buf, "%{:02X}", c).unwrap();
buf
})
}
#[test]

View File

@ -112,11 +112,7 @@ where
let endpoint_fut = self.endpoint.new_service(());
// take extensions or create new one as app data container.
let mut app_data = self
.extensions
.borrow_mut()
.take()
.unwrap_or_else(Extensions::new);
let mut app_data = self.extensions.borrow_mut().take().unwrap_or_default();
Box::pin(async move {
// async data factories

View File

@ -167,7 +167,7 @@ mod tests {
async fn handler_min() {}
#[rustfmt::skip]
#[allow(clippy::too_many_arguments, clippy::just_underscores_and_digits)]
#[allow(clippy::too_many_arguments, clippy::just_underscores_and_digits, clippy::let_unit_value)]
async fn handler_max(
_01: (), _02: (), _03: (), _04: (), _05: (), _06: (),
_07: (), _08: (), _09: (), _10: (), _11: (), _12: (),

View File

@ -92,7 +92,7 @@ pub struct RouteService {
}
impl RouteService {
// TODO: does this need to take &mut ?
#[allow(clippy::needless_pass_by_ref_mut)]
pub fn check(&self, req: &mut ServiceRequest) -> bool {
let guard_ctx = req.guard_ctx();