pub struct InitBuilder<'a> { /* private fields */ }Expand description
Builder for initializing the global options store.
Define optional parameters with with_* methods, then finalize with init()
All settings are optional and independent:
with_directoryoverrides the base directorywith_schemassupplies schemas in memory instead of reading{dir}/schemas/with_additional_schemasadds in-memory schemas alongside whichever base the above selectswith_callbackregisters a callback that fires on every value refresh.with_refresh_thresholdoverrides or disables the staleness threshold for refresh-on-read.
Implementations§
Source§impl<'a> InitBuilder<'a>
impl<'a> InitBuilder<'a>
pub fn new() -> Self
Sourcepub fn with_directory(self, directory: impl Into<PathBuf>) -> Self
pub fn with_directory(self, directory: impl Into<PathBuf>) -> Self
Override the base directory. Expects {directory}/schemas/ and {directory}/values/ subdirectories.
Otherwise, defaults to the fallback chain: SENTRY_OPTIONS_DIR env var, then /etc/sentry-options
Sourcepub fn with_schemas(self, schemas: &'a [(&'a str, &'a str)]) -> Self
pub fn with_schemas(self, schemas: &'a [(&'a str, &'a str)]) -> Self
Provide schemas as in-memory (namespace, json) pairs instead of reading
them from {dir}/schemas/, intended to be used with include_str!.
In other words, overrides schemas supplied locally.
Sourcepub fn with_additional_schemas(self, schemas: &'a [(&'a str, &'a str)]) -> Self
pub fn with_additional_schemas(self, schemas: &'a [(&'a str, &'a str)]) -> Self
Add in-memory (namespace, json) schemas alongside the base regardless
if it came from {dir}/schemas/ or with_schemas.
Errors on a namespace the base already has, rather than shadowing it.
Sourcepub fn with_callback(
self,
callback: impl Fn(&str, f64) + Send + Sync + 'static,
) -> Self
pub fn with_callback( self, callback: impl Fn(&str, f64) + Send + Sync + 'static, ) -> Self
Register a callback that fires (namespace, delay_secs) whenever values
are refreshed with a new generated_at timestamp.
Sourcepub fn with_refresh_threshold(
self,
threshold: impl Into<Option<Duration>>,
) -> Self
pub fn with_refresh_threshold( self, threshold: impl Into<Option<Duration>>, ) -> Self
Overrides the staleness threshold for refresh-on-read.
Defaults to DEFAULT_REFRESH_THRESHOLD (5 seconds). Pass None to
disable refresh-on-read entirely; values then only change via
Options::refresh.
Sourcepub fn init(self) -> Result<()>
pub fn init(self) -> Result<()>
Initialize the global options store from the inputs.
Returns OptionsError::AlreadyInitialized if the store is already
initialized, leaving the existing configuration untouched. Callers that
want a no-op in that case can ignore the error with .ok().
Sourcepub fn build(self) -> Result<Options>
pub fn build(self) -> Result<Options>
Builds an Options instance from the inputs, without initializing
the global store.
Use this when you want to manage the lifetime of the options store yourself, or when you want to have multiple independent options stores in the same process.
Use init if you want to initialize the global store.
Returns an error if the schemas are invalid or the values cannot be loaded.