pub fn settings_path(
platform: Platform,
variable: impl Fn(&str) -> Option<String>,
writable: impl Fn(&Path) -> bool,
temporary: impl FnOnce() -> PathBuf,
) -> PathBufExpand description
Where the settings file is on platform, as music21’s
getSettingsPath finds it.
variable reads the environment, writable says whether a directory
can be written to, and temporary is the directory to fall back on
where the home directory cannot be: music21’s
getDefaultRootTempDir.
use std::path::{Path, PathBuf};
use music21::environment::{settings_path, Platform};
let home = |name: &str| (name == "HOME").then(|| "/home/me".to_owned());
let found = settings_path(Platform::Nix, home, |_: &Path| true, || PathBuf::from("/tmp/music21"));
assert_eq!(found, PathBuf::from("/home/me/.music21rc"));
let found = settings_path(Platform::Nix, |_: &str| None, |_: &Path| true, || PathBuf::from("/tmp/music21"));
assert_eq!(found, PathBuf::from("/tmp/music21/.music21rc"));