diff options
author | alyx <alyx@aleteoryx.me> | 2024-04-01 19:00:57 -0400 |
---|---|---|
committer | alyx <alyx@aleteoryx.me> | 2024-04-01 19:00:57 -0400 |
commit | 22c2e4e2db9ad9d892ed5fb63d92254677f6dafd (patch) | |
tree | c3132945f32d1ca5741848a504b48f09a599bafb /src/cache.rs | |
parent | dc6875ce18a48d314f0576528ebd7dc9e5e2a1b8 (diff) | |
download | lfm_embed-22c2e4e2db9ad9d892ed5fb63d92254677f6dafd.tar.gz lfm_embed-22c2e4e2db9ad9d892ed5fb63d92254677f6dafd.tar.bz2 lfm_embed-22c2e4e2db9ad9d892ed5fb63d92254677f6dafd.zip |
Reliable user info; Font refactor
Hit a few more endpoints to fix missing images, fallback to default album art just in case.
Refactor the font cache into its own file.
Diffstat (limited to 'src/cache.rs')
-rw-r--r-- | src/cache.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/cache.rs b/src/cache.rs index 0e8fd4d..a6f25fa 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -1,5 +1,14 @@ -use std::{future::Future, time::*, collections::HashMap, hash::Hash}; +use std::future::Future; +use std::time::*; +use std::collections::HashMap; +use std::hash::Hash; +use std::sync::Arc; +use std::pin::Pin; + +use tokio::sync::RwLock; + use reqwest::StatusCode; + #[derive(Debug)] pub struct AsyncCache<K, V, F> { func: F, @@ -66,3 +75,7 @@ where self.get(key).await.cloned() } } + +pub type CacheFuture<Output> = Pin<Box<(dyn Future<Output = Result<Output, (StatusCode, &'static str)>> + Send + Sync)>>; +pub type CacheGetter<Output> = fn(&String) -> CacheFuture<Output>; +pub type Cache<Output> = Arc<RwLock<AsyncCache<String, Output, CacheGetter<Output>>>>; |