Skip to main content

AccountRegionStore

Struct AccountRegionStore 

Source
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>

Source

pub fn new() -> Self

Create a new empty store.

Source

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.

Source

pub fn get(&self, account: &AccountId, region: &AwsRegion) -> Option<Arc<T>>

Get the state for the given account and region, if it exists.

Source

pub fn remove(&self, account: &AccountId, region: &AwsRegion) -> Option<Arc<T>>

Remove the state for the given account and region.

Source

pub fn reset(&self)

Reset all state in the store.

Source

pub fn len(&self) -> usize

Number of (account, region) entries.

Source

pub fn is_empty(&self) -> bool

Whether the store is empty.

Trait Implementations§

Source§

impl<T: Debug + Default + Send + Sync> Debug for AccountRegionStore<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default + Send + Sync> Default for AccountRegionStore<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.