pub struct ArtifactCache { /* private fields */ }Expand description
Cache keyed by ArtifactId that stores typed values behind Arc<dyn Any>.
§Examples
use std::sync::Arc;
use uselesskey_core::srp::cache::ArtifactCache;
use uselesskey_core::srp::identity::{ArtifactId, DerivationVersion};
let cache = ArtifactCache::new();
let id = ArtifactId::new("domain:rsa", "issuer", b"RS256", "good", DerivationVersion::V1);
// Insert once, retrieve many times
cache.insert_if_absent_typed(id.clone(), Arc::new(42u32));
let value = cache.get_typed::<u32>(&id).unwrap();
assert_eq!(*value, 42);Implementations§
Source§impl ArtifactCache
impl ArtifactCache
Sourcepub fn new() -> ArtifactCache
pub fn new() -> ArtifactCache
Create an empty artifact cache.
Sourcepub fn get_typed<T>(&self, id: &ArtifactId) -> Option<Arc<T>>
pub fn get_typed<T>(&self, id: &ArtifactId) -> Option<Arc<T>>
Retrieve a typed value by id.
Panics if the id exists with a different concrete type.
Sourcepub fn insert_if_absent_typed<T>(&self, id: ArtifactId, value: Arc<T>) -> Arc<T>
pub fn insert_if_absent_typed<T>(&self, id: ArtifactId, value: Arc<T>) -> Arc<T>
Insert a typed value if the id is vacant and return the winning cached value.
Panics if an existing value for the same id has a different concrete type.
Trait Implementations§
Source§impl Debug for ArtifactCache
impl Debug for ArtifactCache
Source§impl Default for ArtifactCache
impl Default for ArtifactCache
Source§fn default() -> ArtifactCache
fn default() -> ArtifactCache
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ArtifactCache
impl !RefUnwindSafe for ArtifactCache
impl Send for ArtifactCache
impl Sync for ArtifactCache
impl Unpin for ArtifactCache
impl UnsafeUnpin for ArtifactCache
impl !UnwindSafe for ArtifactCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more