I mean location for application database and other files for system user, like ~/.config/some_app in Linux
But maybe that's incorrect for apps managed by cargo, for example it would be ~/.cargo/some_app or similar isolated namespace like for Flatpak or similar package managers.
And if this specific namespace available in Rust ecosystem, how can I retrieve it in main.rs?
Cargo is not in the business of package management of installed applications (as opposed to libraries), with the exception of cargo install which is very much not a full-featured package manager and you should not plan to use for anything but Rust developer tools. And, there are no Rust-specific rules or conventions for installed Rust software, whether or not you use cargo install.
That said, there is a general answer to where you should put your config: you should use the platform’s conventional directory or means of specifying the directory, and a library such as directories can do that for you in a cross-platform way. You'll tell it a name for your application, and it'll tell you the appropriate directory to create and write files into.
If you do that, your application should automatically cooperate with things like Flatpak, because directories will consult the appropriate environment variables and fall back to an appropriate default if they are not set.
currently I'm using following implementation by GTK and STD API
let mut profile_path = gtk::glib::user_config_dir();
profile_path.push(env!("CARGO_PKG_NAME"));
if let Err(e) = std::fs::create_dir_all(&profile_path) {
// ..
}
Just worried CARGO_PKG_NAME dir could be taken by another app. But when I use the cargo's directory, it will be never overwritten as the namespace would be always separated and not dependent from system
Just worried CARGO_PKG_NAME dir could be taken by another app.
There is no perfect solution to this, but various platforms have different conventions for how to reduce this type of conflict. For example, on Windows, it's conventional to use a path like .../Your Organization Name Here/Your Application Name Here/. Other platforms make other choices. If you use directories, you will provide this information and it will generate the appropriate platform-specific path. Don't make up your own naming scheme — it increases the risk of conflicts, and annoys users who like applications to put their files what their platform says they should do.