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