Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 #![warn(missing_docs)]
2 //! *Put your app's data in the right place on every platform*
3 //!
4 //! # Usage
5 //!
6 //! ```rust
7 //! use app_dirs2::*; // or app_dirs::* if you've used package alias in Cargo.toml
8 //!
9 //! const APP_INFO: AppInfo = AppInfo{name: "CoolApp", author: "SuperDev"};
10 //!
11 //! fn main () {
12 //! // Where should I store my app's per-user configuration data?
13 //! println!("{:?}", get_app_root(AppDataType::UserConfig, &APP_INFO));
14 //! // Windows: "%APPDATA%\SuperDev\CoolApp"
15 //! // (e.g.: "C:\Users\Rusty\AppData\Roaming\SuperDev\CoolApp")
16 //! // macOS: "$HOME/Library/Application Support/CoolApp"
17 //! // (e.g.: "/Users/Rusty/Library/Application Support/CoolApp")
18 //! // *nix: "$HOME/.config/CoolApp" (or "$XDG_CONFIG_HOME/CoolApp", if defined)
19 //! // (e.g.: "/home/rusty/.config/CoolApp")
20 //! // Android: "/data/user/<userid>/<app.package.name>/CoolApp"
21 //! // (e.g.: "/data/user/0/org.super_dev.cool_app/CoolApp")
22 //!
23 //! // How about nested cache data?
24 //! println!("{:?}", get_app_dir(AppDataType::UserCache, &APP_INFO, "cache/images"));
25 //! // Windows: "%LOCALAPPDATA%\SuperDev\CoolApp\cache\images"
26 //! // (e.g.: "C:\Users\Rusty\AppData\Local\SuperDev\CoolApp\cache\images")
27 //! // macOS: "$HOME/Library/Caches/CoolApp/cache/images"
28 //! // (e.g.: "/Users/Rusty/Library/Caches/CoolApp/cache/images")
29 //! // *nix: "$HOME/.cache/CoolApp/cache/images"
30 //! // (or "$XDG_CACHE_HOME/CoolApp/cache/images", if defined)
31 //! // (e.g.: "/home/rusty/.cache/CoolApp/cache/images")
32 //! // Android: "/data/user/<userid>/<app.package.name>/cache/CoolApp"
33 //! // (e.g.: "/data/user/0/org.super_dev.cool_app/cache/CoolApp")
34 //!
35 //! // Remove "get_" prefix to recursively create nonexistent directories:
36 //! // app_root(AppDataType::UserConfig, &APP_INFO)
37 //! // app_dir(AppDataType::UserCache, &APP_INFO, "cache/images")
38 //! }
39 //! ```
40
41 mod common;
42 pub use crate::common::*;
43 mod imp;
44 pub use crate::imp::*;
45 mod utils;
46 pub use crate::utils::*;
47
48 #[cfg(test)]
49 mod tests {
50 use super::*;
51 use crate::AppDataType::*;
52 #[test]
53 fn it_works() {
54 let info = AppInfo {
55 name: "Awesome App",
56 author: "Dedicated Dev",
57 };
58 let path = "/.not-hidden/subfolder!/with?/uni.code/¡Olé!/";
59 let types = [UserConfig, UserData, UserCache, SharedData, SharedConfig];
60 for &t in types.iter() {
61 println!("{:?} data root = {:?}", t, get_data_root(t));
62 println!("{:?} app root = {:?}", t, get_app_root(t, &info));
63 println!("{:?} data dir = {:?}", t, get_app_dir(t, &info, path));
64 }
65 }
66 }