pub struct ConsentStore { /* private fields */ }Expand description
In-memory façade over ConsentFile with a Signal<ConsentState>
for widget binding.
Clone is cheap: both the SettingsFile handle and the Signal
are Rc-shared internally.
When constructed with an attached SettingsStore (via
ConsentStore::with_settings_mirror), every write also updates
the per-scope SettingsKey<bool> constants in
crate::scopes so power users editing general.toml directly
see the same state. The mirror is one-way (consent → settings); we
don’t watch the settings keys for changes because the consent file
is always the source of truth.
Implementations§
Source§impl ConsentStore
impl ConsentStore
Sourcepub fn open(
paths: &AppPaths,
delay: Duration,
current_event_schema: u32,
current_endpoint: &str,
) -> Result<Self, SettingsFileError>
pub fn open( paths: &AppPaths, delay: Duration, current_event_schema: u32, current_endpoint: &str, ) -> Result<Self, SettingsFileError>
Open the consent file at paths.config_file("telemetry-consent").
Applies the event-schema re-prompt rule: if the user previously
consented to an older event-schema version (or to a different
endpoint), the persisted state is reset to Unknown and the
widget will re-prompt on first display.
Sourcepub fn with_settings_mirror(self, settings: SettingsStore) -> Self
pub fn with_settings_mirror(self, settings: SettingsStore) -> Self
Attach a SettingsStore for one-way mirror of the per-scope
toggles into the app’s general.toml. Called by
TelemetryBundle::open once the store is available. Idempotent
— passing None is a no-op; calling twice replaces the
previously-attached store.
Sourcepub fn state_signal(&self) -> Signal<ConsentState>
pub fn state_signal(&self) -> Signal<ConsentState>
The reactive state. Bind directly to the consent widget.
Sourcepub fn is_granted(&self) -> bool
pub fn is_granted(&self) -> bool
true iff ConsentState::is_granted holds. Convenience for
the dispatch tap which gates emission.
Sourcepub fn grant(
&self,
scope: ConsentScope,
endpoint: &str,
) -> Result<(), SettingsFileError>
pub fn grant( &self, scope: ConsentScope, endpoint: &str, ) -> Result<(), SettingsFileError>
User accepted, with the given scope. Persists decided_at and
the current event-schema version so future schema bumps will
re-prompt correctly.
Sourcepub fn deny(&self) -> Result<(), SettingsFileError>
pub fn deny(&self) -> Result<(), SettingsFileError>
User explicitly declined. No events emitted; queue is left alone (caller’s responsibility to discard if appropriate).
Sourcepub fn withdraw(&self) -> Result<(), SettingsFileError>
pub fn withdraw(&self) -> Result<(), SettingsFileError>
User withdrew previously-given consent. Same persistence as
deny; semantically distinct in the widget UI.
Sourcepub fn reset(&self) -> Result<(), SettingsFileError>
pub fn reset(&self) -> Result<(), SettingsFileError>
Reset to Unknown — used by the mode-switch flow before
re-prompting.
Sourcepub fn set_or_grant_scope(
&self,
endpoint: &str,
f: impl FnOnce(&mut ConsentScope),
) -> Result<bool, SettingsFileError>
pub fn set_or_grant_scope( &self, endpoint: &str, f: impl FnOnce(&mut ConsentScope), ) -> Result<bool, SettingsFileError>
Mutate the granted scope in place. If the current state is
Unknown, transitions to Granted with the mutated default
scope (so flipping a single toggle on first run grants
consent for that one scope only).
Denied is preserved — the user must explicitly withdraw the
“no” before scope toggles take effect. Returns Ok(true) if
the mutation was applied, Ok(false) if Denied blocked it.
Used by the consent widget for individual scope toggles.
Sourcepub fn set_scope(
&self,
f: impl FnOnce(&mut ConsentScope),
) -> Result<bool, SettingsFileError>
pub fn set_scope( &self, f: impl FnOnce(&mut ConsentScope), ) -> Result<bool, SettingsFileError>
Mutate the granted scope in place (e.g. user toggles
crash_reports from the settings widget).
Returns Ok(false) and is a no-op when the state is
Denied or Unknown — the widget must call grant()
first to install a base scope. Returns Ok(true) when the
closure was invoked and the new scope persisted.
Sourcepub fn flush_now(&self) -> Result<(), SettingsFileError>
pub fn flush_now(&self) -> Result<(), SettingsFileError>
Force a synchronous flush to disk.
Trait Implementations§
Source§impl Clone for ConsentStore
impl Clone for ConsentStore
Source§fn clone(&self) -> ConsentStore
fn clone(&self) -> ConsentStore
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more