Skip to content

Commit

Permalink
cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel-B-D committed May 3, 2024
1 parent 140f7b6 commit ec8882b
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 34 deletions.
1 change: 1 addition & 0 deletions saphir/examples/macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl UserController {
}
}

#[allow(dead_code)]
struct ApiKeyMiddleware(String);

#[middleware]
Expand Down
9 changes: 5 additions & 4 deletions saphir/src/file/content_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// license: https://github.com/dekellum/hyperx/blob/master/LICENSE
// source: https://github.com/dekellum/hyperx/blob/master/src/header/common/content_range.rs

use std::fmt::Display;
use crate::error::SaphirError;
use std::str::FromStr;

Expand Down Expand Up @@ -98,8 +99,8 @@ impl FromStr for ContentRange {
}
}

impl ToString for ContentRange {
fn to_string(&self) -> String {
impl Display for ContentRange {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
ContentRange::Bytes { range, instance_length } => {
let mut string = "bytes ".to_owned();
Expand All @@ -118,9 +119,9 @@ impl ToString for ContentRange {
string.push('*')
}

string
write!(f, "{}", string)
}
ContentRange::Unregistered { ref unit, ref resp } => format!("{} {}", unit, resp),
ContentRange::Unregistered { ref unit, ref resp } => write!(f, "{} {}", unit, resp),
}
}
}
13 changes: 7 additions & 6 deletions saphir/src/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::{
io::{Cursor as CursorSync, Write},
str::FromStr,
};
use std::fmt::Display;
use tokio::io::ReadBuf;

mod cache;
Expand Down Expand Up @@ -212,13 +213,13 @@ impl FromStr for Compression {
}
}

impl ToString for Compression {
fn to_string(&self) -> String {
impl Display for Compression {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Compression::Deflate => "deflate".to_string(),
Compression::Gzip => "gzip".to_string(),
Compression::Brotli => "br".to_string(),
_ => "".to_string(),
Compression::Deflate => write!(f, "deflate"),
Compression::Gzip => write!(f, "gzip"),
Compression::Brotli => write!(f, "br"),
_ => write!(f, ""),
}
}
}
Expand Down
19 changes: 10 additions & 9 deletions saphir/src/file/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// license: https://github.com/dekellum/hyperx/blob/master/LICENSE
// source: https://github.com/dekellum/hyperx/blob/master/src/header/common/range.rs

use std::fmt::Display;
use crate::error::SaphirError;
use std::str::FromStr;

Expand Down Expand Up @@ -104,18 +105,18 @@ impl ByteRangeSpec {
}
}

impl ToString for ByteRangeSpec {
fn to_string(&self) -> String {
impl Display for ByteRangeSpec {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
ByteRangeSpec::FromTo(from, to) => format!("{}-{}", from, to),
ByteRangeSpec::Last(pos) => format!("-{}", pos),
ByteRangeSpec::AllFrom(pos) => format!("{}-", pos),
ByteRangeSpec::FromTo(from, to) => write!(f, "{}-{}", from, to),
ByteRangeSpec::Last(pos) => write!(f, "-{}", pos),
ByteRangeSpec::AllFrom(pos) => write!(f, "{}-", pos),
}
}
}

impl ToString for Range {
fn to_string(&self) -> String {
impl Display for Range {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
Range::Bytes(ref ranges) => {
let mut string = "bytes=".to_owned();
Expand All @@ -127,9 +128,9 @@ impl ToString for Range {
string.push_str(&range.to_string())
}

string
write!(f, "{}", string)
}
Range::Unregistered(ref unit, ref range_str) => format!("{}={}", unit, range_str),
Range::Unregistered(ref unit, ref range_str) => write!(f, "{}={}", unit, range_str),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion saphir/src/http_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl HttpContext {
.get(OPERATION_ID_HEADER)
.and_then(|h| h.to_str().ok())
.and_then(|op_id_str| operation::OperationId::from_str(op_id_str).ok())
.unwrap_or_else(operation::OperationId::new);
.unwrap_or_default();
*request.operation_id_mut() = operation_id;
let state = State::Before(Box::new(request));
let router = Some(router);
Expand Down
1 change: 1 addition & 0 deletions saphir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
//! *_More feature will be added in the future_*
#![allow(clippy::match_like_matches_macro)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![allow(clippy::empty_docs)]

#[macro_use]
extern crate log;
Expand Down
2 changes: 1 addition & 1 deletion saphir/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ where

pub fn build(self) -> Server {
Server {
listener_config: self.listener.unwrap_or_else(ListenerBuilder::new).build(),
listener_config: self.listener.unwrap_or_default().build(),
stack: Stack {
router: self.router.build(),
middlewares: self.middlewares.build(),
Expand Down
6 changes: 5 additions & 1 deletion saphir/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::{
iter::FromIterator,
str::FromStr,
sync::atomic::AtomicU64,
fmt::Write,
};

// TODO: Add possibility to match any route like /page/<path..>/view
Expand Down Expand Up @@ -392,7 +393,10 @@ impl UriPathMatcher {
let mut segments = path_segments.clone();
if Self::match_start(start, &mut segments) && Self::match_end(end, &mut segments) {
if let Some(name) = wildcard_capture_name {
let value = segments.iter().map(|&s| format!("/{}", s)).collect();
let value = segments.iter().fold(String::new(), |mut o, &s| {
let _ = write!(o, "/{}", s);
o
});
captures.insert(name.clone(), value);
}
} else {
Expand Down
1 change: 0 additions & 1 deletion saphir_cli/src/openapi/generate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,6 @@ by using the --package flag."
}
let values = raw[5..(len - 1)]
.split(&[',', '|'][..])
.into_iter()
.map(|v| v.trim().trim_start_matches(char_is_quote).trim_end_matches(char_is_quote).to_string())
.collect::<Vec<_>>();
let values_len = values.len();
Expand Down
20 changes: 9 additions & 11 deletions saphir_cli/src/openapi/generate/response_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl Gen {
for (code, type_name) in pairs {
if !type_name.is_empty() {
if let Some(mut anonymous_type) = self.openapitype_from_raw(method.impl_item.im.item.scope, type_name.as_str()) {
anonymous_type.name = name.clone();
anonymous_type.name.clone_from(&name);
vec.push((
Some(code),
ResponseInfo {
Expand Down Expand Up @@ -274,17 +274,15 @@ impl Gen {
}
}
}
} else {
if let Some(type_path) = type_path {
let anonymous_type = self.openapitype_from_raw(method.impl_item.im.item.scope, type_path.as_str());
if let Some(mut anonymous_type) = anonymous_type {
if let Some(name) = name {
anonymous_type.name = Some(name);
}

res.1.type_info = None;
res.1.anonymous_type = Some(anonymous_type);
} else if let Some(type_path) = type_path {
let anonymous_type = self.openapitype_from_raw(method.impl_item.im.item.scope, type_path.as_str());
if let Some(mut anonymous_type) = anonymous_type {
if let Some(name) = name {
anonymous_type.name = Some(name);
}

res.1.type_info = None;
res.1.anonymous_type = Some(anonymous_type);
}
}
}
Expand Down

0 comments on commit ec8882b

Please sign in to comment.