pub struct MultiAccountState<T> { /* private fields */ }Expand description
Account-partitioned state container.
Holds one T per account id. The default_account_id is pre-created at
startup so unauthenticated requests (which fall back to --account-id)
always have a state to land in.
Implementations§
Source§impl<T: AccountState> MultiAccountState<T>
impl<T: AccountState> MultiAccountState<T>
Sourcepub fn new(default_account_id: &str, region: &str, endpoint: &str) -> Self
pub fn new(default_account_id: &str, region: &str, endpoint: &str) -> Self
Create a new container, pre-populating the default account.
Sourcepub fn map<U>(&self, f: impl FnMut(&T) -> U) -> MultiAccountState<U>
pub fn map<U>(&self, f: impl FnMut(&T) -> U) -> MultiAccountState<U>
Project account states while preserving the container’s routing defaults.
Sourcepub fn map_into<U>(self, f: impl FnMut(&str, T) -> U) -> MultiAccountState<U>
pub fn map_into<U>(self, f: impl FnMut(&str, T) -> U) -> MultiAccountState<U>
Consume the container, converting every account state while keeping the container’s routing defaults. Used by snapshot migrations that change the per-account state type.
Sourcepub fn get_or_create(&mut self, account_id: &str) -> &mut T
pub fn get_or_create(&mut self, account_id: &str) -> &mut T
Get or lazily create the state for account_id.
When a new account is created, AccountState::inherit_from is called
with the default account’s state so services can propagate shared
resources (e.g. body caches).
Sourcepub fn get_or_create_with<F>(&mut self, account_id: &str, init: F) -> &mut T
pub fn get_or_create_with<F>(&mut self, account_id: &str, init: F) -> &mut T
Get or lazily create the state for account_id, then run init on
the newly created state. The callback is only invoked when the account
is freshly created, not on subsequent lookups.
Sourcepub fn get(&self, account_id: &str) -> Option<&T>
pub fn get(&self, account_id: &str) -> Option<&T>
Read-only lookup. Returns None if the account has never been seen.
Sourcepub fn get_mut(&mut self, account_id: &str) -> Option<&mut T>
pub fn get_mut(&mut self, account_id: &str) -> Option<&mut T>
Mutable lookup without auto-creation.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &T)>
pub fn iter(&self) -> impl Iterator<Item = (&str, &T)>
Iterate over all account states (read-only).
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = (&str, &mut T)>
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&str, &mut T)>
Iterate over all account states (mutable).
Sourcepub fn default_account_id(&self) -> &str
pub fn default_account_id(&self) -> &str
The default account id configured via --account-id.
Sourcepub fn default_mut(&mut self) -> &mut T
pub fn default_mut(&mut self) -> &mut T
Mutable reference to the default account’s state (always exists).
Sourcepub fn default_ref(&self) -> &T
pub fn default_ref(&self) -> &T
Reference to the default account’s state (always exists).
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset all accounts back to empty state. The default account is recreated; all other accounts are dropped.
Sourcepub fn reset_account(&mut self, account_id: &str)
pub fn reset_account(&mut self, account_id: &str)
Reset one account back to empty state, leaving every other account untouched. An account with no state yet stays absent.
Sourcepub fn find_account<F>(&self, predicate: F) -> Option<&str>
pub fn find_account<F>(&self, predicate: F) -> Option<&str>
Find the first account whose state satisfies predicate and return
the account id. Useful for resolving globally-unique resources (e.g.
S3 bucket names) back to their owning account.
Sourcepub fn account_count(&self) -> usize
pub fn account_count(&self) -> usize
Number of accounts with state.
Source§impl<T: AccountState> MultiAccountState<RegionalState<T>>
impl<T: AccountState> MultiAccountState<RegionalState<T>>
Sourcepub fn regional(&self, account_id: &str, region: &str) -> Option<&T>
pub fn regional(&self, account_id: &str, region: &str) -> Option<&T>
The state of account_id in region, None when either has never
been touched. Never creates anything, so reads and misses leave no
empty region behind.
Sourcepub fn regional_mut(&mut self, account_id: &str, region: &str) -> &mut T
pub fn regional_mut(&mut self, account_id: &str, region: &str) -> &mut T
The state of account_id in region, creating both on first use.
A newly created region inherits shared resources (see
AccountState::inherit_from) from a region the account already has,
or, for an account’s first region, from the default account’s state in
that region (else any default-account region), the way a new account
inherits from the default account in MultiAccountState.
Sourcepub fn regional_get_mut(
&mut self,
account_id: &str,
region: &str,
) -> Option<&mut T>
pub fn regional_get_mut( &mut self, account_id: &str, region: &str, ) -> Option<&mut T>
The state of account_id in region without creating either.
Sourcepub fn by_arn(&self, arn: &str) -> Option<&T>
pub fn by_arn(&self, arn: &str) -> Option<&T>
The state of the account and region an ARN names, without creating
either. None when the ARN carries no account or region.
Sourcepub fn by_arn_mut(&mut self, arn: &str) -> Option<&mut T>
pub fn by_arn_mut(&mut self, arn: &str) -> Option<&mut T>
Mutable Self::by_arn.
Sourcepub fn default_regional_mut(&mut self) -> &mut T
pub fn default_regional_mut(&mut self) -> &mut T
The default account’s state in the server’s default region, created on first use.
Sourcepub fn default_regional(&self) -> Option<&T>
pub fn default_regional(&self) -> Option<&T>
The default account’s state in the server’s default region, None
until something creates it.
Source§impl<T: SplitByRegion> MultiAccountState<T>
impl<T: SplitByRegion> MultiAccountState<T>
Sourcepub fn into_regional(self) -> MultiRegionState<T>
pub fn into_regional(self) -> MultiRegionState<T>
Convert a legacy account-partitioned container into an (account, region)-partitioned one, splitting every account’s state by region.