Skip to main content

Module dirs

Module dirs 

Source
Expand description

Where an application keeps what it writes for itself: its state, its logs, its crash reports. Read from the environment, as each platform names these places:

Experimental: may change in any release (docs/stability.md).
StateLogs
Linux and BSD$XDG_STATE_HOME/<app> (~/.local/state/<app>)<state>/logs
macOS~/Library/Application Support/<app>~/Library/Logs/<app>
Windows%LOCALAPPDATA%\<app><state>\logs

Settings go to the configuration folder (config_dir). Crash reports go to <state>/crashes. Compiled files go to the platform’s cache directory (cache_dir, egui_pop_tokens::cache). Inside a Flatpak sandbox, XDG_STATE_HOME points into the application’s own directory, so the same code finds the sandbox’s place.

Owned rather than dirs or directories (MIT OR Apache-2.0): three environment variables, and those crates have no state directory on macOS and Windows anyway.

let dir = egui_pop_platform::dirs::state_dir_with("demo", |name| match name {
    "XDG_STATE_HOME" => Some("/state".into()),
    _ => None,
});
if cfg!(all(unix, not(target_os = "macos"))) {
    assert_eq!(dir, Some("/state/demo".into()));
}

Functions§

cache_dir
Where egui-pop keeps the files it compiles for the application (<platform cache>/<app>/egui-pop): the directory of egui_pop_tokens::cache::Cache::for_app.
config_dir
The application’s configuration folder, where its settings are kept (AppBuilder::persist_in_config): ~/.config/<app>, ~/Library/Application Support/<app>, %APPDATA%\<app>. The application’s configuration folder (see the module).
config_dir_with
The application’s configuration folder, where its settings are kept (AppBuilder::persist_in_config): ~/.config/<app>, ~/Library/Application Support/<app>, %APPDATA%\<app>. The application’s configuration folder, from the environment env gives (None: the variables it needs are missing, or on the web).
crash_dir
The application’s crash report directory: <state>/crashes.
log_dir
The application’s log directory (see the module).
pid
This process’s id; 0 on the web, which has no processes (std::process::id panics there).
reveal
Opens a file or a folder with what the system opens it with (xdg-open, open, explorer); returns at once.
state_dir
The application’s state directory (see the module).
state_dir_with
The application’s state directory, from the environment env gives (none: the variables it needs are missing).
temp_dir
The system’s temporary directory, the last resort when the environment names no place. The web has neither a file system nor a temporary directory (std::env::temp_dir panics there): a relative, empty path, where writes fail and are given up.