1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Rust][confy] confyが読み込む設定ファイルのファイルパス

Posted at

confyを使って設定ファイルを読み込もうとしたら、読み込まれるファイルパスが結構わからなかったのでメモ。

Starting with version 0.4.0 the configuration file are stored in the expected place for your system. See the directories crates for more information. Before version 0.4.0, the configuration file was written in the current directory.

0.4以降はdirectories見てねってことだけど、、わからん、、、

pub fn load<T: Serialize + DeserializeOwned + Default>(name: &str) -> Result<T, ConfyError> {
    let project = ProjectDirs::from("rs", "", name).ok_or(ConfyError::BadConfigDirectoryStr)?;

    let config_dir_str = get_configuration_directory_str(&project)?;

    let path: PathBuf = [config_dir_str, &format!("{}.{}", name, EXTENSION)].iter().collect();

    load_path(path)
}

src見てやっと理解。

    let config: Config = confy::load("issue").unwrap();

こんな感じで name を issue にした場合、

Linux:   /home/__username__/.config/issue/issue.toml
Windows: C:\Users\__username__\AppData\Roaming\issue\issue.toml
macOS:   /Users/__username__/Library/Preferences/rs.issue/issue.toml

こうなる。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?