A better Rust ATProto crate

modified vendored cache impl

Orual cbd55399 2e4e31c5

Changed files
+61 -58
crates
jacquard-identity
src
jacquard-oauth
mini-moka-vendored
examples
+4 -4
Cargo.lock
··· 2262 2263 [[package]] 2264 name = "jacquard" 2265 - version = "0.9.3" 2266 dependencies = [ 2267 "bytes", 2268 "clap", ··· 2389 2390 [[package]] 2391 name = "jacquard-derive" 2392 - version = "0.9.3" 2393 dependencies = [ 2394 "heck 0.5.0", 2395 "inventory", ··· 2432 2433 [[package]] 2434 name = "jacquard-lexgen" 2435 - version = "0.9.3" 2436 dependencies = [ 2437 "clap", 2438 "clap_complete", ··· 2519 2520 [[package]] 2521 name = "jacquard-repo" 2522 - version = "0.9.3" 2523 dependencies = [ 2524 "anyhow", 2525 "bytes",
··· 2262 2263 [[package]] 2264 name = "jacquard" 2265 + version = "0.9.4" 2266 dependencies = [ 2267 "bytes", 2268 "clap", ··· 2389 2390 [[package]] 2391 name = "jacquard-derive" 2392 + version = "0.9.4" 2393 dependencies = [ 2394 "heck 0.5.0", 2395 "inventory", ··· 2432 2433 [[package]] 2434 name = "jacquard-lexgen" 2435 + version = "0.9.4" 2436 dependencies = [ 2437 "clap", 2438 "clap_complete", ··· 2519 2520 [[package]] 2521 name = "jacquard-repo" 2522 + version = "0.9.4" 2523 dependencies = [ 2524 "anyhow", 2525 "bytes",
+42 -41
crates/jacquard-identity/src/lib.rs
··· 100 use { 101 crate::lexicon_resolver::ResolvedLexiconSchema, 102 jacquard_common::{smol_str::SmolStr, types::string::Nsid}, 103 - std::time::Duration, 104 }; 105 106 #[cfg(all( ··· 110 use std::sync::Arc; 111 112 // Platform-specific cache implementations 113 - #[cfg(all(feature = "cache", not(target_arch = "wasm32")))] 114 mod cache_impl { 115 /// Native: Use sync cache (thread-safe, no mutex needed) 116 pub type Cache<K, V> = mini_moka::sync::Cache<K, V>; ··· 151 } 152 } 153 154 - #[cfg(all(feature = "cache", target_arch = "wasm32"))] 155 - mod cache_impl { 156 - use std::sync::{Arc, Mutex}; 157 158 - /// WASM: Use unsync cache in Arc<Mutex<_>> (no threads, but need interior mutability) 159 - pub type Cache<K, V> = Arc<Mutex<mini_moka::unsync::Cache<K, V>>>; 160 161 - pub fn new_cache<K, V>(max_capacity: u64, ttl: std::time::Duration) -> Cache<K, V> 162 - where 163 - K: std::hash::Hash + Eq + 'static, 164 - V: Clone + 'static, 165 - { 166 - Arc::new(Mutex::new( 167 - mini_moka::unsync::Cache::builder() 168 - .max_capacity(max_capacity) 169 - .time_to_idle(ttl) 170 - .build(), 171 - )) 172 - } 173 174 - pub fn get<K, V>(cache: &Cache<K, V>, key: &K) -> Option<V> 175 - where 176 - K: std::hash::Hash + Eq + 'static, 177 - V: Clone + 'static, 178 - { 179 - cache.lock().unwrap().get(key).cloned() 180 - } 181 182 - pub fn insert<K, V>(cache: &Cache<K, V>, key: K, value: V) 183 - where 184 - K: std::hash::Hash + Eq + 'static, 185 - V: Clone + 'static, 186 - { 187 - cache.lock().unwrap().insert(key, value); 188 - } 189 190 - pub fn invalidate<K, V>(cache: &Cache<K, V>, key: &K) 191 - where 192 - K: std::hash::Hash + Eq + 'static, 193 - V: Clone + 'static, 194 - { 195 - cache.lock().unwrap().invalidate(key); 196 - } 197 - } 198 199 /// Configuration for resolver caching 200 #[cfg(feature = "cache")]
··· 100 use { 101 crate::lexicon_resolver::ResolvedLexiconSchema, 102 jacquard_common::{smol_str::SmolStr, types::string::Nsid}, 103 + mini_moka::time::Duration, 104 }; 105 106 #[cfg(all( ··· 110 use std::sync::Arc; 111 112 // Platform-specific cache implementations 113 + //#[cfg(all(feature = "cache", not(target_arch = "wasm32")))] 114 + #[cfg(feature = "cache")] 115 mod cache_impl { 116 /// Native: Use sync cache (thread-safe, no mutex needed) 117 pub type Cache<K, V> = mini_moka::sync::Cache<K, V>; ··· 152 } 153 } 154 155 + // #[cfg(all(feature = "cache", target_arch = "wasm32"))] 156 + // mod cache_impl { 157 + // use std::sync::{Arc, Mutex}; 158 159 + // /// WASM: Use unsync cache in Arc<Mutex<_>> (no threads, but need interior mutability) 160 + // pub type Cache<K, V> = Arc<Mutex<mini_moka::unsync::Cache<K, V>>>; 161 162 + // pub fn new_cache<K, V>(max_capacity: u64, ttl: std::time::Duration) -> Cache<K, V> 163 + // where 164 + // K: std::hash::Hash + Eq + 'static, 165 + // V: Clone + 'static, 166 + // { 167 + // Arc::new(Mutex::new( 168 + // mini_moka::unsync::Cache::builder() 169 + // .max_capacity(max_capacity) 170 + // .time_to_idle(ttl) 171 + // .build(), 172 + // )) 173 + // } 174 175 + // pub fn get<K, V>(cache: &Cache<K, V>, key: &K) -> Option<V> 176 + // where 177 + // K: std::hash::Hash + Eq + 'static, 178 + // V: Clone + 'static, 179 + // { 180 + // cache.lock().unwrap().get(key).cloned() 181 + // } 182 183 + // pub fn insert<K, V>(cache: &Cache<K, V>, key: K, value: V) 184 + // where 185 + // K: std::hash::Hash + Eq + 'static, 186 + // V: Clone + 'static, 187 + // { 188 + // cache.lock().unwrap().insert(key, value); 189 + // } 190 191 + // pub fn invalidate<K, V>(cache: &Cache<K, V>, key: &K) 192 + // where 193 + // K: std::hash::Hash + Eq + 'static, 194 + // V: Clone + 'static, 195 + // { 196 + // cache.lock().unwrap().invalidate(key); 197 + // } 198 + // } 199 200 /// Configuration for resolver caching 201 #[cfg(feature = "cache")]
+1
crates/jacquard-oauth/src/resolver.rs
··· 5 use http::{Request, StatusCode}; 6 use jacquard_common::CowStr; 7 use jacquard_common::IntoStatic; 8 use jacquard_common::types::did_doc::DidDocument; 9 use jacquard_common::types::ident::AtIdentifier; 10 use jacquard_common::{http_client::HttpClient, types::did::Did};
··· 5 use http::{Request, StatusCode}; 6 use jacquard_common::CowStr; 7 use jacquard_common::IntoStatic; 8 + use jacquard_common::cowstr::ToCowStr; 9 use jacquard_common::types::did_doc::DidDocument; 10 use jacquard_common::types::ident::AtIdentifier; 11 use jacquard_common::{http_client::HttpClient, types::did::Did};
+1 -1
crates/mini-moka-vendored/src/common.rs
··· 6 pub(crate) mod builder_utils; 7 pub(crate) mod deque; 8 pub(crate) mod frequency_sketch; 9 - pub(crate) mod time; 10 11 // Note: `CacheRegion` cannot have more than four enum variants. This is because 12 // `crate::{sync,unsync}::DeqNodes` uses a `tagptr::TagNonNull<DeqNode<T>, 2>`
··· 6 pub(crate) mod builder_utils; 7 pub(crate) mod deque; 8 pub(crate) mod frequency_sketch; 9 + pub mod time; 10 11 // Note: `CacheRegion` cannot have more than four enum variants. This is because 12 // `crate::{sync,unsync}::DeqNodes` uses a `tagptr::TagNonNull<DeqNode<T>, 2>`
+2 -5
crates/mini-moka-vendored/src/common/concurrent/housekeeper.rs
··· 6 }, 7 }; 8 9 - use crate::common::time::{CheckedTimeOps, Instant}; 10 11 - use std::{ 12 - sync::atomic::{AtomicBool, Ordering}, 13 - time::Duration, 14 - }; 15 16 pub(crate) trait InnerSync { 17 fn sync(&self, max_sync_repeats: usize);
··· 6 }, 7 }; 8 9 + use crate::common::time::{CheckedTimeOps, Duration, Instant}; 10 11 + use std::sync::atomic::{AtomicBool, Ordering}; 12 13 pub(crate) trait InnerSync { 14 fn sync(&self, max_sync_repeats: usize);
+5 -1
crates/mini-moka-vendored/src/common/time.rs
··· 1 - use std::time::Duration; 2 3 pub(crate) mod clock; 4
··· 1 + #[cfg(not(feature = "js"))] 2 + pub type Duration = std::time::Duration; 3 + 4 + #[cfg(feature = "js")] 5 + pub type Duration = web_time::Duration; 6 7 pub(crate) mod clock; 8
+2
crates/mini-moka-vendored/src/lib.rs
··· 66 #[cfg_attr(docsrs, doc(cfg(feature = "sync")))] 67 pub mod sync; 68 69 pub use policy::Policy; 70 71 #[cfg(test)]
··· 66 #[cfg_attr(docsrs, doc(cfg(feature = "sync")))] 67 pub mod sync; 68 69 + pub use common::time; 70 + 71 pub use policy::Policy; 72 73 #[cfg(test)]
+1 -2
crates/mini-moka-vendored/src/sync/base_cache.rs
··· 15 }, 16 deque::{DeqNode, Deque}, 17 frequency_sketch::FrequencySketch, 18 - time::{CheckedTimeOps, Clock, Instant}, 19 CacheRegion, 20 }, 21 Policy, ··· 34 atomic::{AtomicBool, Ordering}, 35 Arc, Mutex, RwLock, 36 }, 37 - time::Duration, 38 }; 39 use triomphe::Arc as TrioArc; 40
··· 15 }, 16 deque::{DeqNode, Deque}, 17 frequency_sketch::FrequencySketch, 18 + time::{CheckedTimeOps, Clock, Duration, Instant}, 19 CacheRegion, 20 }, 21 Policy, ··· 34 atomic::{AtomicBool, Ordering}, 35 Arc, Mutex, RwLock, 36 }, 37 }; 38 use triomphe::Arc as TrioArc; 39
+1 -2
crates/mini-moka-vendored/src/sync/builder.rs
··· 1 use super::Cache; 2 - use crate::{common::builder_utils, common::concurrent::Weigher}; 3 4 use std::{ 5 collections::hash_map::RandomState, 6 hash::{BuildHasher, Hash}, 7 marker::PhantomData, 8 sync::Arc, 9 - time::Duration, 10 }; 11 12 /// Builds a [`Cache`][cache-struct] or with various configuration knobs.
··· 1 use super::Cache; 2 + use crate::{common::builder_utils, common::concurrent::Weigher, common::time::Duration}; 3 4 use std::{ 5 collections::hash_map::RandomState, 6 hash::{BuildHasher, Hash}, 7 marker::PhantomData, 8 sync::Arc, 9 }; 10 11 /// Builds a [`Cache`][cache-struct] or with various configuration knobs.
+1 -1
crates/mini-moka-vendored/src/sync/cache.rs
··· 6 housekeeper::{Housekeeper, InnerSync}, 7 Weigher, WriteOp, 8 }, 9 time::Instant, 10 }, 11 Policy, ··· 18 fmt, 19 hash::{BuildHasher, Hash}, 20 sync::Arc, 21 - time::Duration, 22 }; 23 24 /// A thread-safe concurrent in-memory cache built upon [`dashmap::DashMap`][dashmap].
··· 6 housekeeper::{Housekeeper, InnerSync}, 7 Weigher, WriteOp, 8 }, 9 + time::Duration, 10 time::Instant, 11 }, 12 Policy, ··· 19 fmt, 20 hash::{BuildHasher, Hash}, 21 sync::Arc, 22 }; 23 24 /// A thread-safe concurrent in-memory cache built upon [`dashmap::DashMap`][dashmap].
+1 -1
examples/app_password_create_post.rs
··· 23 let args = Args::parse(); 24 25 let (session, auth) = 26 - MemoryCredentialSession::authenticated(args.input, args.password, None).await?; 27 println!("Signed in as {}", auth.handle); 28 29 let agent: Agent<_> = Agent::from(session);
··· 23 let args = Args::parse(); 24 25 let (session, auth) = 26 + MemoryCredentialSession::authenticated(args.input, args.password, None, None).await?; 27 println!("Signed in as {}", auth.handle); 28 29 let agent: Agent<_> = Agent::from(session);