From 2feec01f58ce903d07d53bb1b79dc6b448b1a146 Mon Sep 17 00:00:00 2001 From: alyx Date: Fri, 12 Jan 2024 12:40:49 -0500 Subject: Clippy --- src/config.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index 49b515e..e635f4a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -14,13 +14,25 @@ use tokio::sync::RwLock; use handlebars::{Handlebars, handlebars_helper}; use duration_str as ds; -static INTERNAL_THEMES: &[(&'static str, &'static str)] = &[("plain", include_str!("themes/plain.hbs"))]; +type CacheFuture = Pin> + Send + Sync)>>; +type CacheGetter = fn(&String) -> CacheFuture; +type Cache = Arc>>>; + +type FontFuture = CacheFuture>; +type FontGetter = CacheGetter>; +type FontCache = Cache>; + +type UserFuture = CacheFuture>; +type UserGetter = CacheGetter>; +type UserCache = Cache>; + +static INTERNAL_THEMES: &[(&str, &str)] = &[("plain", include_str!("themes/plain.hbs"))]; pub static STATE: LazyLock> = LazyLock::new(|| { State::new() }); -fn user_getter(username: &String) -> Pin, (StatusCode, &'static str)>> + Send + Sync)>> { +fn user_getter(username: &String) -> UserFuture { let username = urlencoding::encode(username.as_ref()).to_string(); Box::pin(async move { let userreq = STATE.http.get(format!("https://ws.audioscrobbler.com/2.0/?method=user.getInfo&format=json&user={username}&api_key={}", STATE.lastfm_api_key)) @@ -39,13 +51,13 @@ fn user_getter(username: &String) -> Pin().await .map_err(|e| {log::error!("Couldn't parse user.getRecentTracks for `{username}`: {e}"); (StatusCode::INTERNAL_SERVER_ERROR, "Couldn't parse user.getRecentTracks!")})? - .recenttracks.track.into_iter().nth(0).ok_or((StatusCode::UNPROCESSABLE_ENTITY, "You need to listen to some songs first!"))?; + .recenttracks.track.into_iter().next().ok_or((StatusCode::UNPROCESSABLE_ENTITY, "You need to listen to some songs first!"))?; Ok(Arc::new((userinfo, tracksinfo))) }) } -fn font_getter(fontname: &String) -> Pin, (StatusCode, &'static str)>> + Send + Sync)>> { +fn font_getter(fontname: &String) -> FontFuture { let fontname = urlencoding::encode(fontname.as_ref()).to_string(); Box::pin(async move { let Some(google_api_key) = STATE.google_api_key.clone() @@ -70,10 +82,7 @@ fn font_getter(fontname: &String) -> Pin Pin, (StatusCode, &'static str)>> + Send + Sync)>>; -type UserCache = Arc, UserGetter>>>; -type FontGetter = fn(&String) -> Pin, (StatusCode, &'static str)>> + Send + Sync)>>; -type FontCache = Arc, FontGetter>>>; + #[derive(Debug)] enum Whitelist { Exclusive{cache: UserCache, whitelist: BTreeSet}, @@ -142,7 +151,7 @@ impl State { whitelist: { let load_whitelist = || -> Option> { var("LFME_WHITELIST").ok().map( - |w| w.split(",").map(|s| s.trim().to_string()).collect() + |w| w.split(',').map(|s| s.trim().to_string()).collect() ) }; -- cgit v1.2.3-54-g00ecf