pub struct AccountRegionStore<T: Default + Send + Sync> { /* private fields */ }Expand description
Thread-safe, multi-account, multi-region state store.
Each (account, region) pair gets its own isolated state instance of type T.
Uses DashMap for lock-free concurrent access.
§Examples
use rustack_core::{AccountRegionStore, AccountId, AwsRegion};
#[derive(Debug, Default)]
struct MyServiceState {
counter: std::sync::atomic::AtomicU64,
}
let store = AccountRegionStore::<MyServiceState>::new();
let state = store.get_or_create(&AccountId::default(), &AwsRegion::default());
state.counter.fetch_add(1, std::sync::atomic::Ordering::Relaxed);Implementations§
Source§impl<T: Default + Send + Sync> AccountRegionStore<T>
impl<T: Default + Send + Sync> AccountRegionStore<T>
Sourcepub fn get_or_create(&self, account: &AccountId, region: &AwsRegion) -> Arc<T>
pub fn get_or_create(&self, account: &AccountId, region: &AwsRegion) -> Arc<T>
Get or create the state for the given account and region.
If the state does not exist, a new default instance is created atomically.
Sourcepub fn get(&self, account: &AccountId, region: &AwsRegion) -> Option<Arc<T>>
pub fn get(&self, account: &AccountId, region: &AwsRegion) -> Option<Arc<T>>
Get the state for the given account and region, if it exists.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for AccountRegionStore<T>
impl<T> !RefUnwindSafe for AccountRegionStore<T>
impl<T> Send for AccountRegionStore<T>
impl<T> Sync for AccountRegionStore<T>
impl<T> Unpin for AccountRegionStore<T>
impl<T> UnsafeUnpin for AccountRegionStore<T>
impl<T> UnwindSafe for AccountRegionStore<T>where
T: RefUnwindSafe,
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