pub struct SettingsStore { /* private fields */ }Expand description
The settings document (<data_dir>/<namespace>/settings.json) and the explorer sidebar’s
record (explorer.json, an object of key to text). The TypeScript side owns the settings
shape, so the store keeps one opaque JSON object. Only a successful open is cached; a failed
open is reported on every call and retried.
Implementations§
Source§impl SettingsStore
impl SettingsStore
Sourcepub fn new(data_dir: Option<PathBuf>, namespace: impl Into<String>) -> Self
pub fn new(data_dir: Option<PathBuf>, namespace: impl Into<String>) -> Self
data_dir is the host’s per-user data directory (None when unavailable) and
namespace the app’s folder name beneath it.
Sourcepub fn persisted_diagnostics_enabled(&self) -> bool
pub fn persisted_diagnostics_enabled(&self) -> bool
The diagnostics choice for the native log gate before the settings document is opened (early startup events): an absent or unreadable choice means on (the default).
Sourcepub fn startup_diagnostics_enabled(&self) -> bool
pub fn startup_diagnostics_enabled(&self) -> bool
Open the settings document and answer the diagnostics choice, so the opt-out is in force before the first native event. If the document cannot be opened, recording stays off.
Sourcepub fn get(
&self,
key: &str,
with_revision: Option<bool>,
) -> Result<Value, WorkspaceError>
pub fn get( &self, key: &str, with_revision: Option<bool>, ) -> Result<Value, WorkspaceError>
Read a durable value. The SETTINGS_KEY key is the settings document (JSON string, or
null when nothing has ever been saved). With with_revision, the document read answers
{ value, revision } where revision is the committed revision from the store (0 when
nothing is stored). Other keys (the explorer record) read the explorer document.
Sourcepub fn set(
&self,
key: &str,
value: &str,
expected_revision: Option<u64>,
merge: Option<bool>,
) -> Result<SettingsWrite, WorkspaceError>
pub fn set( &self, key: &str, value: &str, expected_revision: Option<u64>, merge: Option<bool>, ) -> Result<SettingsWrite, WorkspaceError>
Persist a value: the settings document, or (any other key) the explorer document.
For the settings document, expected_revision makes the commit a compare-and-swap on the
store’s committed revision (a stale one fails as a write conflict, nothing is written),
and merge applies value as a top-level patch (null removes a key) inside the store’s
write lock instead of replacing the whole document. The answer is { value, revision }
with the committed document; other keys answer null.