JsonWrapper

Struct JsonWrapper 

Source
pub struct JsonWrapper {
    pub raw_data: String,
    pub data: Value,
}

Fields§

§raw_data: String§data: Value

Implementations§

Source§

impl JsonWrapper

Source

pub fn new(file_path: &str) -> Result<Self, Box<dyn Error>>

创建一个新的配置实例

该函数会读取指定路径的配置文件,解析JSON格式的内容,并创建配置对象

§参数
  • file_path - 配置文件的路径字符串引用
§返回值

返回Result类型,成功时包含配置实例,失败时包含IO错误

§错误

当文件读取失败或JSON解析失败时会返回相应的错误

Source

pub fn from_string(conf_string: &str) -> Result<Self>

Source

pub fn get<'a, 'b: 'a>(&'a self, key: &'b str) -> Vec<&'a Value>

获取指定键对应的值列表

该函数通过创建一个值包装器来访问内部数据,并返回与给定键关联的所有值。

§参数
  • key - 要查找的静态字符串键
§返回值

返回一个包含所有匹配值的引用向量

Source

pub fn get_one<'a, 'b: 'a>(&'a self, key: &'b str) -> &'a Value

获取指定键对应的第一个值

§参数
  • key - 要查找的键名,必须是静态字符串
§返回值

返回键对应值的引用

§注意

如果键不存在或对应的值为空,会触发panic

Trait Implementations§

Source§

impl Debug for JsonWrapper

Source§

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

Formats the value using the given formatter. 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> 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.