pub struct YamlWrapper {
pub raw_data: String,
pub data: Value,
}Expand description
Yaml 数据读取
use dev_tool::YamlWrapper;
#[test]
fn test_config_util() {
// 读取配置文件
let wrapper = YamlWrapper::new("docs/config.yaml").unwrap();
// 直接将yaml字符串转换成YamlWrapper
// let warpper = YamlWrapper::from_string("......").unwrap();
// 不管是对象,还是数组,都是直接通过`.`操作。address是对象,children是数组,name是children中对象的一个属性
let x = wrapper.get("address.children.name");
println!("address.children.name = {:?}", x);
// get方法是获取数组,而get_one获取的是第一个元素
let x = wrapper.get_one("address.x.y").as_str().unwrap();
println!("address.x.y = {}", x);
}Fields§
§raw_data: String§data: ValueImplementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for YamlWrapper
impl RefUnwindSafe for YamlWrapper
impl Send for YamlWrapper
impl Sync for YamlWrapper
impl Unpin for YamlWrapper
impl UnwindSafe for YamlWrapper
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