Update to tokio 1, fix clippy lints
This commit is contained in:
parent
2d5da08bad
commit
5db1dbc96c
840
Cargo.lock
generated
840
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
10
Cargo.toml
10
Cargo.toml
|
@ -8,11 +8,13 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
rand = "0.7"
|
||||
reqwest = { version = "0.10", default-features = false, features = ["json", "rustls-tls"] }
|
||||
rand = "0.8"
|
||||
reqwest = { version = "0.11", default-features = false, features = [
|
||||
"json",
|
||||
"rustls-tls",
|
||||
] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
toml = "0.5"
|
||||
tokio = { version = "0.3", features = ["full"] }
|
||||
tokio-compat-02 = "0.1"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
url = { version = "2.0", features = ["serde"] }
|
||||
|
|
|
@ -9,7 +9,7 @@ fn select(variants: &HashSet<String>, weights: &[(u64, String)], rng: &mut impl
|
|||
.collect::<Vec<_>>();
|
||||
|
||||
let total = filtered.iter().fold(0, |acc, (weight, _)| acc + weight);
|
||||
let selected = rng.gen_range(0, total);
|
||||
let selected = rng.gen_range(0..total);
|
||||
|
||||
let (s, _) = filtered
|
||||
.iter()
|
||||
|
@ -58,15 +58,10 @@ impl Entry {
|
|||
{
|
||||
let variant = self.gen_variant(weights, rng);
|
||||
|
||||
if forbids
|
||||
.iter()
|
||||
.find(|f| {
|
||||
f.iter()
|
||||
.find(|f| f.name == self.name && f.variants.contains(&variant))
|
||||
.is_some()
|
||||
})
|
||||
.is_some()
|
||||
{
|
||||
if forbids.iter().any(|f| {
|
||||
f.iter()
|
||||
.any(|f| f.name == self.name && f.variants.contains(&variant))
|
||||
}) {
|
||||
return String::new();
|
||||
}
|
||||
|
||||
|
@ -81,7 +76,7 @@ impl Entry {
|
|||
|
||||
fn gen_variant(&self, weights: Option<&[(u64, String)]>, rng: &mut impl Rng) -> String {
|
||||
if let Some(weights) = weights {
|
||||
return select(&self.variants, &weights, rng);
|
||||
return select(&self.variants, weights, rng);
|
||||
}
|
||||
|
||||
self.variants
|
||||
|
@ -113,6 +108,7 @@ impl Entry {
|
|||
})
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn gen_next<'a, 'b>(
|
||||
&'a self,
|
||||
building: String,
|
||||
|
@ -280,16 +276,11 @@ impl Depend {
|
|||
forbids.push(local_forbids);
|
||||
|
||||
let entry = entries
|
||||
.into_iter()
|
||||
.iter()
|
||||
.find(|entry| entry.name == self.depends)
|
||||
.expect(&format!("Missing entry for {}", self.depends));
|
||||
.unwrap_or_else(|| panic!("Missing entry for {}", self.depends));
|
||||
|
||||
let value = entry.gen(
|
||||
self.weights.as_ref().map(Vec::as_slice),
|
||||
entries,
|
||||
forbids,
|
||||
rng,
|
||||
);
|
||||
let value = entry.gen(self.weights.as_deref(), entries, forbids, rng);
|
||||
|
||||
forbids.pop();
|
||||
|
||||
|
@ -323,7 +314,7 @@ impl Config {
|
|||
.entries
|
||||
.iter()
|
||||
.find(|entry| entry.name == self.root)
|
||||
.expect(&format!("Invalid config: no entry called {}", self.root));
|
||||
.unwrap_or_else(|| panic!("Invalid config: no entry called {}", self.root));
|
||||
|
||||
let mut forbids = Vec::new();
|
||||
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -2,8 +2,7 @@ use anyhow::{anyhow, Result};
|
|||
use rand::{thread_rng, Rng};
|
||||
use reqwest::{header::HeaderMap, Client};
|
||||
use std::{path::Path, time::Duration};
|
||||
use tokio::{fs::File, prelude::*, time::interval};
|
||||
use tokio_compat_02::FutureExt;
|
||||
use tokio::{fs::File, io::AsyncReadExt, io::AsyncWriteExt, time::interval};
|
||||
use url::Url;
|
||||
|
||||
mod description;
|
||||
|
@ -79,7 +78,6 @@ impl Mastodon {
|
|||
scope: "read write",
|
||||
})
|
||||
.send()
|
||||
.compat()
|
||||
.await?;
|
||||
|
||||
if !res.status().is_success() {
|
||||
|
@ -89,7 +87,7 @@ impl Mastodon {
|
|||
));
|
||||
}
|
||||
|
||||
let token: Token = res.json().compat().await?;
|
||||
let token: Token = res.json().await?;
|
||||
Ok(token)
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +118,7 @@ impl Config {
|
|||
Ok(config)
|
||||
}
|
||||
|
||||
async fn to_state(
|
||||
async fn into_state(
|
||||
self,
|
||||
token_path: impl AsRef<Path>,
|
||||
name: name::Config,
|
||||
|
@ -175,7 +173,6 @@ impl State {
|
|||
visibility: "unlisted",
|
||||
})
|
||||
.send()
|
||||
.compat()
|
||||
.await?;
|
||||
|
||||
if !res.status().is_success() {
|
||||
|
@ -202,7 +199,7 @@ async fn main() -> Result<()> {
|
|||
let duration = Duration::from_secs(60) * config.timing.duration;
|
||||
let mut ticker = interval(duration);
|
||||
|
||||
let state = config.to_state("Token.toml", name, description).await?;
|
||||
let state = config.into_state("Token.toml", name, description).await?;
|
||||
|
||||
let mut rng = thread_rng();
|
||||
loop {
|
||||
|
|
Loading…
Reference in a new issue