Skip to main content

rtcom_config/
paths.rs

1//! Default filesystem locations for rtcom profiles.
2
3use std::path::PathBuf;
4
5use directories::ProjectDirs;
6
7/// Returns the default path at which rtcom reads / writes its profile.
8///
9/// Resolves to the platform config directory via XDG / Apple / Known Folder
10/// conventions, e.g. `$XDG_CONFIG_HOME/rtcom/default.toml` on Linux.
11/// Returns `None` when no home directory can be determined (unusual — only
12/// hits sandboxed environments without `HOME`/`USERPROFILE`).
13#[must_use]
14pub fn default_profile_path() -> Option<PathBuf> {
15    ProjectDirs::from("", "", "rtcom").map(|dirs| dirs.config_dir().join("default.toml"))
16}
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21
22    #[test]
23    fn default_profile_path_has_rtcom_and_default_toml() {
24        // env may lack HOME/XDG_CONFIG_HOME in CI sandboxes; tolerate None.
25        if let Some(p) = default_profile_path() {
26            assert!(p.ends_with("default.toml"), "tail: {}", p.display());
27            let as_str = p.to_string_lossy();
28            assert!(
29                as_str.contains("rtcom"),
30                "path must include rtcom: {as_str}"
31            );
32        }
33    }
34}