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
impl YamlConfig
Sourcepub fn scripts_dir() -> PathBuf
pub fn scripts_dir() -> PathBuf
获取脚本存储目录: ~/.jdata/scripts/
Sourcepub fn report_dir() -> PathBuf
pub fn report_dir() -> PathBuf
获取日报目录: ~/.jdata/report/
Sourcepub fn report_file_path(&self) -> PathBuf
pub fn report_file_path(&self) -> PathBuf
获取日报文件路径(优先使用用户配置,否则使用默认路径 ~/.jdata/report/week_report.md)
Sourcepub fn is_verbose(&self) -> bool
pub fn is_verbose(&self) -> bool
是否是 verbose 模式
Sourcepub fn get_section_mut(
&mut self,
s: &str,
) -> Option<&mut BTreeMap<String, String>>
pub fn get_section_mut( &mut self, s: &str, ) -> Option<&mut BTreeMap<String, String>>
获取指定 section 的可变引用
Sourcepub fn get_property(&self, section: &str, key: &str) -> Option<&String>
pub fn get_property(&self, section: &str, key: &str) -> Option<&String>
获取某个 section 中指定 key 的值
Sourcepub fn set_property(&mut self, section: &str, key: &str, value: &str)
pub fn set_property(&mut self, section: &str, key: &str, value: &str)
设置某个 section 中的键值对并保存
Sourcepub fn remove_property(&mut self, section: &str, key: &str)
pub fn remove_property(&mut self, section: &str, key: &str)
删除某个 section 中的键并保存
Sourcepub fn rename_property(&mut self, section: &str, old_key: &str, new_key: &str)
pub fn rename_property(&mut self, section: &str, old_key: &str, new_key: &str)
重命名某个 section 中的键
Sourcepub fn all_section_names(&self) -> &'static [&'static str]
pub fn all_section_names(&self) -> &'static [&'static str]
获取所有已知的 section 名称
Sourcepub fn alias_exists(&self, alias: &str) -> bool
pub fn alias_exists(&self, alias: &str) -> bool
判断别名是否存在于任何 section 中(用于 open 命令判断)
Sourcepub fn get_path_by_alias(&self, alias: &str) -> Option<&String>
pub fn get_path_by_alias(&self, alias: &str) -> Option<&String>
根据别名获取路径(依次从 path、inner_url、outer_url 中查找)
Sourcepub fn collect_alias_envs(&self) -> Vec<(String, String)>
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
impl Clone for YamlConfig
Source§fn clone(&self) -> YamlConfig
fn clone(&self) -> YamlConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for YamlConfig
impl Debug for YamlConfig
Source§impl Default for YamlConfig
impl Default for YamlConfig
Source§fn default() -> YamlConfig
fn default() -> YamlConfig
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for YamlConfig
impl<'de> Deserialize<'de> for YamlConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for YamlConfig
impl RefUnwindSafe for YamlConfig
impl Send for YamlConfig
impl Sync for YamlConfig
impl Unpin for YamlConfig
impl UnsafeUnpin for YamlConfig
impl UnwindSafe for YamlConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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