Skip to content

Commit

Permalink
Merge pull request lnx-search#21 from robjtede/clippy
Browse files Browse the repository at this point in the history
address many clippy lints
  • Loading branch information
ChillFish8 authored Nov 7, 2021
2 parents cff6ec0 + 1b65635 commit 854ecad
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 36 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Lint

on:
push:
branches: [ master ]
pull_request:
types: [ opened, synchronize, reopened ]

jobs:
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: rustfmt
override: true
- name: Rustfmt Check
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: clippy
override: true
- name: Clippy Check
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --workspace --all-features --tests --examples --bins -- -Dclippy::todo
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
types: [ opened, synchronize, reopened ]

env:
CARGO_TERM_COLOR: always
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn parse_duration(duration: &str) -> Result<Duration> {
dur += add_to
}

if dur.as_secs() <= 0 {
if dur.as_secs() == 0 {
return Err(Error::msg(format!(
"failed to extract any valid duration from {}",
duration
Expand Down
7 changes: 3 additions & 4 deletions src/proto/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ where

let ts = Instant::now();

if let Err(_) = send_request.ready().await {
if send_request.ready().await.is_err() {
return Ok(());
}

Expand Down Expand Up @@ -144,9 +144,8 @@ where
while start.elapsed() < time_for {
let res = self.connect(counter).await;

match res {
Ok(val) => return Ok(val),
Err(_) => (),
if let Ok(val) = res {
return Ok(val);
}

sleep(Duration::from_millis(200)).await;
Expand Down
5 changes: 3 additions & 2 deletions src/proto/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Connect for HttpsConnector {
.connect(self.domain.as_ref(), stream)
.await?;

Ok(handshake(stream, protocol).await?)
handshake(stream, protocol).await
})
}
}
Expand All @@ -87,7 +87,8 @@ where
.await?;

let handle = tokio::spawn(async move {
if let Err(_) = connection.await {}
// TODO: handle error
let _ = connection.await;

// Connection died
// Should reconnect and log
Expand Down
2 changes: 1 addition & 1 deletion src/proto/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl ClientBuilder {
}

fn uri_host(&self) -> &str {
&self.parsed_uri.uri.host().unwrap()
self.parsed_uri.uri.host().unwrap()
}

fn uri_scheme(&self) -> Scheme {
Expand Down
2 changes: 1 addition & 1 deletion src/proto/tcp_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl CustomTcpStream {
pub fn new(stream: TcpStream, counter: Arc<AtomicUsize>) -> Self {
Self {
inner: stream,
counter: counter,
counter,
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/proto/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::str::FromStr;

use hyper::Uri;

#[allow(clippy::upper_case_acronyms)]
#[derive(Clone, Copy)]
pub enum Scheme {
HTTP,
Expand Down Expand Up @@ -46,7 +47,7 @@ pub struct ParsedUri {

impl ParsedUri {
pub async fn parse_and_lookup(s: &str) -> Result<Self, AnyError> {
let uri = Uri::from_str(&s)?;
let uri = Uri::from_str(s)?;

let scheme = Scheme::from(uri.scheme_str());

Expand All @@ -64,11 +65,11 @@ impl ParsedUri {
}

async fn get_preferred_ip(host: &str, port: u16) -> Result<SocketAddr, AnyError> {
let mut addrs = tokio::net::lookup_host((host, port)).await?;
let addrs = tokio::net::lookup_host((host, port)).await?;

let mut res = Err("host lookup failed".into());

while let Some(addr) = addrs.next() {
for addr in addrs {
if addr.is_ipv4() {
return Ok(addr);
}
Expand Down
28 changes: 6 additions & 22 deletions src/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tokio::time::Duration;

use crate::utils::format_data;

fn get_percentile(request_times: &Vec<Duration>, pct: f64) -> Duration {
fn get_percentile(request_times: &[Duration], pct: f64) -> Duration {
let mut len = request_times.len() as f64 * pct;
if len < 1.0 {
len = 1.0;
Expand Down Expand Up @@ -99,28 +99,12 @@ impl WorkerResult {

/// Calculates the max latency overall from all requests.
pub fn max_request_latency(&self) -> Duration {
let max = self
.request_times
.iter()
.map(|dur| dur)
.max()
.map(|res| *res)
.unwrap_or(Duration::default());

max
self.request_times.iter().max().copied().unwrap_or_default()
}

/// Calculates the min latency overall from all requests.
pub fn min_request_latency(&self) -> Duration {
let min = self
.request_times
.iter()
.map(|dur| dur)
.min()
.map(|res| *res)
.unwrap_or(Duration::default());

min
self.request_times.iter().min().copied().unwrap_or_default()
}

/// Calculates the variance between all requests
Expand Down Expand Up @@ -185,7 +169,7 @@ impl WorkerResult {
}

pub fn display_latencies(&mut self) {
let modified = 1000 as f64;
let modified = 1000_f64;
let avg = self.avg_request_latency().as_secs_f64() * modified;
let max = self.max_request_latency().as_secs_f64() * modified;
let min = self.min_request_latency().as_secs_f64() * modified;
Expand Down Expand Up @@ -230,7 +214,7 @@ impl WorkerResult {
println!(" Transfer:");
println!(
" Total: {:^7} Transfer Rate: {:^7}",
format!("{}", display_total).as_str().bright_cyan(),
display_total.as_str().bright_cyan(),
format!("{}/Sec", display_rate).as_str().bright_cyan()
)
}
Expand All @@ -248,7 +232,7 @@ impl WorkerResult {

println!("+ {:-^15} + {:-^15} +", "", "",);

let modifier = 1000 as f64;
let modifier = 1000_f64;
println!(
"| {:^15} | {:^15} |",
"99.9%",
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub type BoxedFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;

const GIGABYTE: f64 = (1024 * 1024 * 1024) as f64;
const MEGABYTE: f64 = (1024 * 1024) as f64;
const KILOBYTE: f64 = 1024 as f64;
const KILOBYTE: f64 = 1024_f64;

/// Dirt simple div mod function.
pub fn div_mod(main: u64, divider: u64) -> (u64, u64) {
Expand Down

0 comments on commit 854ecad

Please sign in to comment.