2 releases
0.1.1 | Mar 2, 2021 |
---|---|
0.1.0 | Mar 2, 2021 |
#1318 in Filesystem
24 downloads per month
Used in mcfg
48KB
679 lines
Crate xdirs
Additional functions for application paths, based on dirs-next.
This crate extends the set of paths used by an application to store data and configuration. It
compliments functions such as cache_dir
, config_dir
, and data_dir
with versions with a
suffix _for
that take an application name. It is not the case that, for all of such paths, it
is safe to append an application name to the generic path, and so these additional functions will
ensure the correct construction of the application-specific path.
This is an alternative to the directories-next and maintains a closer interface to dirs-next.
Generic Form | dirs | Application-Specific Form |
---|---|---|
cache_dir |
Yes | cache_dir_for |
config_dir |
Yes | config_dir_for |
data_dir |
Yes | data_dir_for |
data_local_dir |
Yes | data_local_dir_for |
favorites_dir |
No | favorites_dir_for |
log_dir |
No | log_dir_for |
preference_dir |
No | preference_dir_for |
template_dir |
Yes | template_dir_for |
The column dirs denotes whether the generic form is present in the dirs or dirs-next crate.
Example
use xdirs::{application_dir, config_dir_for, log_dir_for};
const APP_NAME: &str = env!("CARGO_PKG_NAME");
let where_is_my_app_installed = application_dir();
let where_do_i_read_my_config = config_dir_for(APP_NAME);
let where_do_i_write_log_files = log_dir_for(APP_NAME);
Additional Functions
The following may be used to determine the location for installed applications.
application_dir
application_shared_dir
user_application_dir
Finally, for systems that support a notion of an application container or bundle, the following will provide the location to these directories. Currently these only provide values on macOS.
app_container_dir_for
app_container_executable_dir_for
user_app_container_dir_for
user_app_container_executable_dir_for
As is the case for dirs-next, this library provides the location of these directories by leveraging the mechanisms defined by
- the XDG base directory and the XDG user directory specifications on Linux,
- the Known Folder system on Windows, and
- the Standard Directories on macOS.
Changes
Version 0.1.1
- Added: example and text to README.
- Fixed: documentation links and table of functions.
Version 0.1.0
- Initial version: all primary functions tested on Linux (Ubuntu), macOS, and Windows.
- Documentation: included function doc with the same form as dirs_next.
TODO
- Support WASM target, dist-next does.
- Look into flatpack, app-image, or snap app container support.
Dependencies
~52–520KB