Skip to main content

ConsentStore

Struct ConsentStore 

Source
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

Source

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.

Source

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.

Source

pub fn state_signal(&self) -> Signal<ConsentState>

The reactive state. Bind directly to the consent widget.

Source

pub fn is_granted(&self) -> bool

true iff ConsentState::is_granted holds. Convenience for the dispatch tap which gates emission.

Source

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.

Source

pub fn deny(&self) -> Result<(), SettingsFileError>

User explicitly declined. No events emitted; queue is left alone (caller’s responsibility to discard if appropriate).

Source

pub fn withdraw(&self) -> Result<(), SettingsFileError>

User withdrew previously-given consent. Same persistence as deny; semantically distinct in the widget UI.

Source

pub fn reset(&self) -> Result<(), SettingsFileError>

Reset to Unknown — used by the mode-switch flow before re-prompting.

Source

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.

Source

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.

Source

pub fn flush_now(&self) -> Result<(), SettingsFileError>

Force a synchronous flush to disk.

Source

pub fn path(&self) -> &Path

The on-disk path. Surfaced verbatim by the consent widget for transparency (the user can inspect or delete the file by hand).

Trait Implementations§

Source§

impl Clone for ConsentStore

Source§

fn clone(&self) -> ConsentStore

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ConsentStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.