Skip to content

Commit 0eac08a

Browse files
authored
document settings save location and TOML format (#24830)
Fixes #24699 Documents where SettingsPlugin writes settings on Linux, macOS, Windows, and WASM, and that the format is TOML. ## Test plan - [x] cargo doc -p bevy-settings --no-deps
1 parent e6f39cb commit 0eac08a

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

crates/bevy_settings/src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,34 @@ use store_wasm::SettingsStore;
5151
/// afford one, use a reverse domain based on the URL of your repo (GitHub, GitLab, Codeberg
5252
/// and so on).
5353
///
54+
/// # Storage location and format
55+
///
56+
/// Settings are stored as **TOML** files. Each [`SettingsGroup`] type becomes a top-level section
57+
/// in the file. The default filename is `settings`, which produces `settings.toml`.
58+
///
59+
/// On desktop platforms, files are written to `{preferences_dir()}/{app_name}/{filename}.toml`,
60+
/// where [`preferences_dir()`](bevy_platform::dirs::preferences_dir) is provided by
61+
/// [`bevy_platform::dirs::preferences_dir`]. With `app_name = "com.example.myapp"` and the default
62+
/// filename, typical paths are:
63+
///
64+
/// - Linux: `~/.config/com.example.myapp/settings.toml` (or under `$XDG_CONFIG_HOME` when set)
65+
/// - macOS: `~/Library/Preferences/com.example.myapp/settings.toml`
66+
/// - Windows: `%LocalAppData%\com.example.myapp\settings.toml`
67+
///
68+
/// On `wasm32`, settings are stored in browser `localStorage` under the key
69+
/// `{app_name}-{filename}` as a TOML string.
70+
///
71+
/// A file with one [`SettingsGroup`] named `counter` might look like:
72+
///
73+
/// ```toml
74+
/// [counter]
75+
/// count = 5
76+
/// enabled = true
77+
/// ```
78+
///
79+
/// Use `settings_group(file = "...")` on a [`SettingsGroup`] to write to a different file in the
80+
/// same app directory (see [`SettingsGroup`] for details).
81+
///
5482
/// Adding this plugin causes an immediate load of settings (from either the filesystem or
5583
/// browser local storage, depending on platform).
5684
///

examples/app/settings.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
//! Its value persists between app sessions via settings.
55
//!
66
//! On desktop, if you quit the app and then restart it, the counter value should display
7-
//! the most recent value the app had before exiting.
7+
//! the most recent value the app had before exiting. Settings are saved as TOML at
8+
//! `{preferences_dir}/org.bevy.examples.settings/settings.toml` (see [`SettingsPlugin`]).
89
//! On web, if you navigate away and then come back to the window, the counter
910
//! should display the most recent value the app had before navigating away.
1011
use std::time::Duration;

0 commit comments

Comments
 (0)