Expand description
Settings storage: an application’s preferences in a TOML file in the platform config directory.
theme = "nordic"
language = "tr"
[editor]
tab-width = 4Keys are dotted paths ("editor.tab-width"); the dots become TOML tables. Loading never
fails: a broken file yields located Diagnostics, broken entries are skipped and the rest
is used. Saving goes through atomic_write, so a crash never leaves half a file; a file
that could not be read completely is kept under its own name with .bak added
(settings.toml.bak, code.conf.bak) before it is first overwritten.
The module also holds what every application needs around its own files, settings or not:
config_dir and data_dir for the two folders a platform gives an application and
state_dir and cache_dir for what it remembers between runs and what it can rebuild,
atomic_write for writing any file safely, AppLock for “one instance at a time” and
InstanceLock for “wake me when the last instance closes”,
machine_name for keeping one file per machine in a folder several machines share, and
FolderWatch for hearing about changes in a folder the moment the system sees them.
Applications made to be used together keep their settings in one folder: a Family names
it, gives each application its <app>.conf file and a folder beside it, and
Family::adopt moves an application’s settings there from the folder it used on its own.
documents_dir and Family::workspace_dir say where the user’s own work goes.
Family::preferences resolves the language, theme and icons the family’s applications share,
and Family::set changes one of them for every application or for one.
An application can describe its keys with a Schema. Loading then checks every key against
it, and with Settings::self_heal on it repairs the file: unknown keys are removed, invalid
values are replaced by their default, and each repair is reported. Optional keys
(Schema::optional) are kept only while valid, and keys under an open prefix
(Schema::open) are kept as they are. A missing key is never written: reading it gives
None and the application falls back to its default.
Structs§
- AppLock
- An advisory lock on a file, held by the running process for as long as this value lives.
- Family
- A family of applications that share one settings folder.
- Folder
Change - One change in a watched folder, as
FolderChanges::nextreports it. - Folder
Changes - The waiting side of a
FolderWatch; seeFolderChanges::next. - Folder
Watch - Watches folders for changes the operating system reports, and never polls.
- Instance
Lock - A shared or exclusive advisory lock on a file, held for as long as this value lives.
- Migration
- What
Family::adoptdid: the files it moved and, for everything it left behind, a diagnostic that names the path and says why. - Preferences
- The shared preferences as one application sees them, from
Family::preferences. - Resolved
- A preference’s value together with where it came from.
- Schema
- The settings an application knows: every key with what it may hold and its default.
- Setting
Kind - What an optional key may hold, for
Schema::optional: the same kinds as the builders with a default (Schema::flag,Schema::text,Schema::choice,Schema::check), without the default. - Settings
- An application’s settings: typed values under dotted keys, loaded from and saved to one TOML file.
Enums§
- Folder
Change Kind - What happened in a watched folder; see
FolderChange. - Scope
- Where
Family::setwrites a change: the “In every Quvyta application” choice of a settings screen. - Setting
Value - A value stored in settings.
- Shared
- A preference every application of a family shares.
- Source
- Where a resolved preference came from, so a settings screen can say “follows every Quvyta application” or “only here”.
- Write
Step - A step
atomic_writehas finished, in the order they happen.
Traits§
- Setting
- A Rust type that can be read from and written to settings.
Functions§
- atomic_
write - Writes
contentstopathso that a crash or a power cut leaves either the file that was there before or the new one, never half of either. - atomic_
write_ reporting atomic_write, reporting each step toon_stepas it finishes, for a log or a screen that shows what writing a file safely actually does.- cache_
dir - Where application
appkeeps its cache: files it can rebuild at any time, which the user or the system may delete without losing anything. - config_
dir - Where application
appkeeps its settings. - data_
dir - Where application
appkeeps its own data: records, caches it wants to survive, files it wrote itself. Records are not settings, so they do not live next to them. - documents_
dir - The user’s Documents folder, where an application puts files the user made and wants to find again in a file manager: projects, exports, notes.
- holder_
pid - The process id the lock file names, for a message such as “another instance (12345) is
running”.
Nonewhen the file is missing, empty or holds anything but a number. - machine_
name - The name of this machine, safe to use inside a file name, such as
running-<machine>.toml. - state_
dir - Where application
appkeeps its state: what it remembers between runs that is worth keeping but does not belong to the user’s settings or records, such as the result of its last background check or the tab it was last on.