AppData

Struct AppData 

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

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§

Source§

impl Clone for AppData

Source§

fn clone(&self) -> AppData

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AppData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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
Source§

impl PartialEq for AppData

Source§

fn eq(&self, other: &AppData) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for AppData

Source§

impl StructuralPartialEq for AppData

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.