pub struct AppData {
pub app_name: String,
pub force_local: bool,
}Expand description
§Examples
use app_data::AppData;
let app_data = AppData::default();
let app_data = AppData::new("my_app");Fields§
§app_name: StringThe name of the application, if the storage location is in the system application directory, use this application name as a subdirectory
中文说明
应用名称,如果存储位置在系统应用目录,以此应用名作为子目录force_local: boolWhether to force create the data directory under the startup path
中文说明
是否强制在运行目录下创建 data 目录Implementations§
Source§impl AppData
impl AppData
Sourcepub fn ensure_data_dir(&self) -> Result<PathBuf, AppDataError>
pub fn ensure_data_dir(&self) -> Result<PathBuf, AppDataError>
Return the application data directory according to the search rules, ensuring that the directory is valid and exists
Besides logging, you don’t need to care about this method, just keep track of the data file path
中文说明
按照寻找规则返回应用数据目录,会确保目录有效且存在。 除了记录日志,你并不需要关心此方法,保持关注数据文件路径即可§Examples
use app_data::AppData;
let app_data = AppData::default();
let data_dir = app_data.ensure_data_dir().unwrap();
println!("data_dir: {}", data_dir.display());Sourcepub fn get_file_path(&self, file_name: &str) -> Result<PathBuf, AppDataError>
pub fn get_file_path(&self, file_name: &str) -> Result<PathBuf, AppDataError>
获取数据目录中的文件路径
Get the file path in the data directory
§Examples
use app_data::AppData;
let app_data = AppData::new("my_app");
let file_path = app_data.get_file_path("config.json").unwrap();Trait Implementations§
impl Eq for AppData
impl StructuralPartialEq for AppData
Auto Trait Implementations§
impl Freeze for AppData
impl RefUnwindSafe for AppData
impl Send for AppData
impl Sync for AppData
impl Unpin for AppData
impl UnwindSafe for AppData
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more