Skip to main content

YamlConfig

Struct YamlConfig 

Source
pub struct YamlConfig {
    pub path: BTreeMap<String, String>,
    pub inner_url: BTreeMap<String, String>,
    pub outer_url: BTreeMap<String, String>,
    pub editor: BTreeMap<String, String>,
    pub browser: BTreeMap<String, String>,
    pub vpn: BTreeMap<String, String>,
    pub script: BTreeMap<String, String>,
    pub version: BTreeMap<String, String>,
    pub setting: BTreeMap<String, String>,
    pub log: BTreeMap<String, String>,
    pub report: BTreeMap<String, String>,
    pub extra: BTreeMap<String, Value>,
}
Expand description

YAML 配置文件的完整结构 使用 BTreeMap 保持键的有序性,与 Java 版的 LinkedHashMap 行为一致

Fields§

§path: BTreeMap<String, String>§inner_url: BTreeMap<String, String>§outer_url: BTreeMap<String, String>§editor: BTreeMap<String, String>§browser: BTreeMap<String, String>§vpn: BTreeMap<String, String>§script: BTreeMap<String, String>§version: BTreeMap<String, String>§setting: BTreeMap<String, String>§log: BTreeMap<String, String>§report: BTreeMap<String, String>§extra: BTreeMap<String, Value>

捕获未知的顶级键,保证不丢失任何配置

Implementations§

Source§

impl YamlConfig

Source

pub fn data_dir() -> PathBuf

获取数据根目录: ~/.jdata/

Source

pub fn scripts_dir() -> PathBuf

获取脚本存储目录: ~/.jdata/scripts/

Source

pub fn report_dir() -> PathBuf

获取日报目录: ~/.jdata/report/

Source

pub fn report_file_path(&self) -> PathBuf

获取日报文件路径(优先使用用户配置,否则使用默认路径 ~/.jdata/report/week_report.md)

Source

pub fn load() -> Self

从配置文件加载

Source

pub fn save(&self)

保存配置到文件

Source

pub fn is_verbose(&self) -> bool

是否是 verbose 模式

Source

pub fn get_section(&self, s: &str) -> Option<&BTreeMap<String, String>>

获取指定 section 的不可变引用

Source

pub fn get_section_mut( &mut self, s: &str, ) -> Option<&mut BTreeMap<String, String>>

获取指定 section 的可变引用

Source

pub fn contains(&self, section: &str, key: &str) -> bool

检查某个 section 中是否包含指定的 key

Source

pub fn get_property(&self, section: &str, key: &str) -> Option<&String>

获取某个 section 中指定 key 的值

Source

pub fn set_property(&mut self, section: &str, key: &str, value: &str)

设置某个 section 中的键值对并保存

Source

pub fn remove_property(&mut self, section: &str, key: &str)

删除某个 section 中的键并保存

Source

pub fn rename_property(&mut self, section: &str, old_key: &str, new_key: &str)

重命名某个 section 中的键

Source

pub fn all_section_names(&self) -> &'static [&'static str]

获取所有已知的 section 名称

Source

pub fn alias_exists(&self, alias: &str) -> bool

判断别名是否存在于任何 section 中(用于 open 命令判断)

Source

pub fn get_path_by_alias(&self, alias: &str) -> Option<&String>

根据别名获取路径(依次从 path、inner_url、outer_url 中查找)

Source

pub fn collect_alias_envs(&self) -> Vec<(String, String)>

收集所有别名路径,用于注入脚本执行时的环境变量 返回 Vec<(env_key, value)>,env_key 格式为 J_<ALIAS_UPPER> 别名中的 - 会转换为 _,且全部大写 覆盖 section: path, inner_url, outer_url, script

Trait Implementations§

Source§

impl Clone for YamlConfig

Source§

fn clone(&self) -> YamlConfig

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 YamlConfig

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for YamlConfig

Source§

fn default() -> YamlConfig

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for YamlConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for YamlConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,