Update to tokio 1, fix clippy lints

This commit is contained in:
asonix 2022-12-22 14:28:26 -06:00
parent 2d5da08bad
commit 5db1dbc96c
4 changed files with 321 additions and 571 deletions

840
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -8,11 +8,13 @@ edition = "2018"
[dependencies] [dependencies]
anyhow = "1.0" anyhow = "1.0"
rand = "0.7" rand = "0.8"
reqwest = { version = "0.10", default-features = false, features = ["json", "rustls-tls"] } reqwest = { version = "0.11", default-features = false, features = [
"json",
"rustls-tls",
] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
toml = "0.5" toml = "0.5"
tokio = { version = "0.3", features = ["full"] } tokio = { version = "1", features = ["full"] }
tokio-compat-02 = "0.1"
url = { version = "2.0", features = ["serde"] } url = { version = "2.0", features = ["serde"] }

View file

@ -9,7 +9,7 @@ fn select(variants: &HashSet<String>, weights: &[(u64, String)], rng: &mut impl
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let total = filtered.iter().fold(0, |acc, (weight, _)| acc + weight); 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 let (s, _) = filtered
.iter() .iter()
@ -58,15 +58,10 @@ impl Entry {
{ {
let variant = self.gen_variant(weights, rng); let variant = self.gen_variant(weights, rng);
if forbids if forbids.iter().any(|f| {
.iter() f.iter()
.find(|f| { .any(|f| f.name == self.name && f.variants.contains(&variant))
f.iter() }) {
.find(|f| f.name == self.name && f.variants.contains(&variant))
.is_some()
})
.is_some()
{
return String::new(); return String::new();
} }
@ -81,7 +76,7 @@ impl Entry {
fn gen_variant(&self, weights: Option<&[(u64, String)]>, rng: &mut impl Rng) -> String { fn gen_variant(&self, weights: Option<&[(u64, String)]>, rng: &mut impl Rng) -> String {
if let Some(weights) = weights { if let Some(weights) = weights {
return select(&self.variants, &weights, rng); return select(&self.variants, weights, rng);
} }
self.variants self.variants
@ -113,6 +108,7 @@ impl Entry {
}) })
} }
#[allow(clippy::too_many_arguments)]
fn gen_next<'a, 'b>( fn gen_next<'a, 'b>(
&'a self, &'a self,
building: String, building: String,
@ -280,16 +276,11 @@ impl Depend {
forbids.push(local_forbids); forbids.push(local_forbids);
let entry = entries let entry = entries
.into_iter() .iter()
.find(|entry| entry.name == self.depends) .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( let value = entry.gen(self.weights.as_deref(), entries, forbids, rng);
self.weights.as_ref().map(Vec::as_slice),
entries,
forbids,
rng,
);
forbids.pop(); forbids.pop();
@ -323,7 +314,7 @@ impl Config {
.entries .entries
.iter() .iter()
.find(|entry| entry.name == self.root) .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(); let mut forbids = Vec::new();

View file

@ -2,8 +2,7 @@ use anyhow::{anyhow, Result};
use rand::{thread_rng, Rng}; use rand::{thread_rng, Rng};
use reqwest::{header::HeaderMap, Client}; use reqwest::{header::HeaderMap, Client};
use std::{path::Path, time::Duration}; use std::{path::Path, time::Duration};
use tokio::{fs::File, prelude::*, time::interval}; use tokio::{fs::File, io::AsyncReadExt, io::AsyncWriteExt, time::interval};
use tokio_compat_02::FutureExt;
use url::Url; use url::Url;
mod description; mod description;
@ -79,7 +78,6 @@ impl Mastodon {
scope: "read write", scope: "read write",
}) })
.send() .send()
.compat()
.await?; .await?;
if !res.status().is_success() { 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) Ok(token)
} }
} }
@ -120,7 +118,7 @@ impl Config {
Ok(config) Ok(config)
} }
async fn to_state( async fn into_state(
self, self,
token_path: impl AsRef<Path>, token_path: impl AsRef<Path>,
name: name::Config, name: name::Config,
@ -175,7 +173,6 @@ impl State {
visibility: "unlisted", visibility: "unlisted",
}) })
.send() .send()
.compat()
.await?; .await?;
if !res.status().is_success() { if !res.status().is_success() {
@ -202,7 +199,7 @@ async fn main() -> Result<()> {
let duration = Duration::from_secs(60) * config.timing.duration; let duration = Duration::from_secs(60) * config.timing.duration;
let mut ticker = interval(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(); let mut rng = thread_rng();
loop { loop {