AppData

Struct AppData 

Source
pub struct AppData {
    pub app_name: String,
    pub force_local: bool,
}

Fields§

§app_name: String

The name of the application, if the storage location is in the system application directory, use this application name as a subdirectory

中文说明 应用名称,如果存储位置在系统应用目录,以此应用名作为子目录
§force_local: bool

Whether to force create the data directory under the startup path

中文说明 是否强制在运行目录下创建 data 目录

Implementations§

Source§

impl AppData

Create a new AppData instance

Source

pub fn new(app_name: &str) -> Self

Source

pub fn with_force_local(app_name: &str, force_local: bool) -> Self

Source§

impl AppData

Source

pub fn ensure_data_dir(&self) -> Result<PathBuf>

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());
Source

pub fn get_file_path(&self, file_name: &str) -> Result<PathBuf>

Trait Implementations§

Source§

impl Default for AppData

Source§

fn default() -> Self

Default using CARGO_PKG_NAME as the application name, if CARGO_PKG_NAME is not set, then force_local is true

中文说明 默认使用 `CARGO_PKG_NAME` 作为应用名称,如果 `CARGO_PKG_NAME` 未设置,则`force_local` 为true

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.