Skip to content

Commit

Permalink
fetchpost: clippy:items_after_statements
Browse files Browse the repository at this point in the history
warning: adding items after statements is confusing, since items exist from the start of the scope
   --> src/cmd/fetchpost.rs:378:5
    |
378 |     use std::num::NonZeroU32;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements

warning: adding items after statements is confusing, since items exist from the start of the scope
   --> src/cmd/fetchpost.rs:443:5
    |
443 |     use reqwest::blocking::Client;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements

warning: adding items after statements is confusing, since items exist from the start of the scope
   --> src/cmd/fetchpost.rs:459:5
    |
459 |     use governor::{Quota, RateLimiter};
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements

warning: adding items after statements is confusing, since items exist from the start of the scope
   --> src/cmd/fetchpost.rs:503:5
    |
503 | /     enum ReportKind {
504 | |         Detailed,
505 | |         Short,
506 | |         None,
507 | |     }
    | |_____^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements

warning: adding items after statements is confusing, since items exist from the start of the scope
   --> src/cmd/fetchpost.rs:927:5
    |
927 |     const MINIMUM_WAIT_MS: u64 = 10;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements

warning: adding items after statements is confusing, since items exist from the start of the scope
   --> src/cmd/fetchpost.rs:928:5
    |
928 |     const MIN_WAIT: time::Duration = time::Duration::from_millis(MINIMUM_WAIT_MS);
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements
  • Loading branch information
jqnatividad committed Jan 26, 2023
1 parent f2a69e0 commit 8cb8bab
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/cmd/fetchpost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Common options:
-p, --progressbar Show progress bars. Not valid for stdin.
"#;

use std::{fs, io::Write, thread, time};
use std::{fs, io::Write, num::NonZeroU32, thread, time};

use cached::{
proc_macro::{cached, io_cached},
Expand All @@ -178,6 +178,7 @@ use governor::{
clock::DefaultClock,
middleware::NoOpMiddleware,
state::{direct::NotKeyed, InMemoryState},
Quota, RateLimiter,
};
use indicatif::{HumanCount, MultiProgress, ProgressBar, ProgressDrawTarget};
use log::{
Expand All @@ -188,7 +189,10 @@ use once_cell::sync::{Lazy, OnceCell};
use rand::Rng;
use redis;
use regex::Regex;
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
use reqwest::{
blocking::Client,
header::{HeaderMap, HeaderName, HeaderValue},
};
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use serde_urlencoded;
Expand Down Expand Up @@ -241,6 +245,18 @@ const FETCHPOST_REPORT_SUFFIX: &str = ".fetchpost-report.tsv";
// prioritize decompression schemes. Brotli first, then gzip, then deflate, and * last
static DEFAULT_ACCEPT_ENCODING: &str = "br;q=1.0, gzip;q=0.6, deflate;q=0.4, *;q=0.2";

// for governor/ratelimiter
const MINIMUM_WAIT_MS: u64 = 10;
const MIN_WAIT: time::Duration = time::Duration::from_millis(MINIMUM_WAIT_MS);

// for --report option
#[derive(PartialEq)]
enum ReportKind {
Detailed,
Short,
None,
}

struct RedisConfig {
conn_str: String,
max_pool_size: u32,
Expand Down Expand Up @@ -375,7 +391,6 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
}
}

use std::num::NonZeroU32;
let rate_limit = match args.flag_rate_limit {
0 => NonZeroU32::new(u32::MAX).unwrap(),
1..=1000 => NonZeroU32::new(args.flag_rate_limit).unwrap(),
Expand Down Expand Up @@ -440,8 +455,6 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
};
debug!("HTTP Header: {http_headers:?}");

use reqwest::blocking::Client;

let client_timeout = time::Duration::from_secs(*TIMEOUT_FP_SECS.get().unwrap_or(&30));
let client = Client::builder()
.user_agent(user_agent)
Expand All @@ -456,8 +469,6 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
.timeout(client_timeout)
.build()?;

use governor::{Quota, RateLimiter};

// set rate limiter with allow_burst set to 1 - see https://github.com/antifuchs/governor/issues/39
let limiter =
RateLimiter::direct(Quota::per_second(rate_limit).allow_burst(NonZeroU32::new(1).unwrap()));
Expand Down Expand Up @@ -499,13 +510,6 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
None => args.flag_jql.as_ref().map(std::string::ToString::to_string),
};

#[derive(PartialEq)]
enum ReportKind {
Detailed,
Short,
None,
}

// prepare report
let report = if args.flag_report.to_lowercase().starts_with('d') {
// if it starts with d, its a detailed report
Expand Down Expand Up @@ -924,8 +928,6 @@ fn get_response(
info!("Using URL: {valid_url}");

// wait until RateLimiter gives Okay or we timeout
const MINIMUM_WAIT_MS: u64 = 10;
const MIN_WAIT: time::Duration = time::Duration::from_millis(MINIMUM_WAIT_MS);
let mut limiter_total_wait: u64;
let timeout_secs = unsafe { *TIMEOUT_FP_SECS.get_unchecked() };
let governor_timeout_ms = timeout_secs * 1_000;
Expand Down

0 comments on commit 8cb8bab

Please sign in to comment.