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 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 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.
Trait Implementations§
Source§impl<T: Clone> Clone for MultiAccountState<T>
impl<T: Clone> Clone for MultiAccountState<T>
Source§fn clone(&self) -> MultiAccountState<T>
fn clone(&self) -> MultiAccountState<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more