pub struct StorageOptionsAccessor { /* private fields */ }Expand description
Unified access to storage options with automatic caching and refresh
This struct bundles static storage options with an optional dynamic provider, handling all caching and refresh logic internally. It provides a single entry point for accessing storage options regardless of whether they’re static or dynamic.
§Behavior
- If only static options are provided, returns those options
- If a provider is configured, fetches from provider and caches results
- Automatically refreshes cached options before expiration (based on refresh_offset)
- Uses
expires_at_milliskey to track expiration
§Thread Safety
The accessor is thread-safe and can be shared across multiple tasks. Concurrent refresh attempts are deduplicated using a try-lock mechanism.
Implementations§
Source§impl StorageOptionsAccessor
impl StorageOptionsAccessor
Sourcepub fn with_static_options(options: HashMap<String, String>) -> Self
pub fn with_static_options(options: HashMap<String, String>) -> Self
Create an accessor with only static options (no refresh capability)
The returned accessor will always return the provided options. This is useful when credentials don’t expire or are managed externally.
Sourcepub fn with_provider(provider: Arc<dyn StorageOptionsProvider>) -> Self
pub fn with_provider(provider: Arc<dyn StorageOptionsProvider>) -> Self
Create an accessor with a dynamic provider (no initial options)
The accessor will fetch from the provider on first access and cache the results. Refresh happens automatically before expiration. Uses the default refresh offset (60 seconds) until options are fetched.
§Arguments
provider- The storage options provider for fetching fresh options
Sourcepub fn with_initial_and_provider(
initial_options: HashMap<String, String>,
provider: Arc<dyn StorageOptionsProvider>,
) -> Self
pub fn with_initial_and_provider( initial_options: HashMap<String, String>, provider: Arc<dyn StorageOptionsProvider>, ) -> Self
Create an accessor with initial options and a dynamic provider
Initial options are used until they expire, then the provider is called.
This avoids an immediate fetch when initial credentials are still valid.
The refresh_offset_millis key in initial_options controls refresh timing.
§Arguments
initial_options- Initial storage options to cacheprovider- The storage options provider for refreshing
Sourcepub async fn get_storage_options(&self) -> Result<StorageOptions>
pub async fn get_storage_options(&self) -> Result<StorageOptions>
Get current valid storage options
- Returns cached options if not expired
- Fetches from provider if expired or not cached
- Falls back to initial_options if provider returns None
§Errors
Returns an error if:
- The provider fails to fetch options
- No options are available (no cache, no provider, no initial options)
Sourcepub fn initial_storage_options(&self) -> Option<&HashMap<String, String>>
pub fn initial_storage_options(&self) -> Option<&HashMap<String, String>>
Get the initial storage options without refresh
Returns the initial options that were provided when creating the accessor. This does not trigger any refresh, even if the options have expired.
Sourcepub fn accessor_id(&self) -> String
pub fn accessor_id(&self) -> String
Get the accessor ID for equality/hashing
Returns the provider_id if a provider exists, otherwise generates a stable ID from the initial options hash.
Sourcepub fn has_provider(&self) -> bool
pub fn has_provider(&self) -> bool
Check if this accessor has a dynamic provider
Sourcepub fn refresh_offset(&self) -> Duration
pub fn refresh_offset(&self) -> Duration
Get the refresh offset duration
Sourcepub fn provider(&self) -> Option<&Arc<dyn StorageOptionsProvider>>
pub fn provider(&self) -> Option<&Arc<dyn StorageOptionsProvider>>
Get the storage options provider, if any
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StorageOptionsAccessor
impl !RefUnwindSafe for StorageOptionsAccessor
impl Send for StorageOptionsAccessor
impl Sync for StorageOptionsAccessor
impl Unpin for StorageOptionsAccessor
impl !UnwindSafe for StorageOptionsAccessor
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more