pub struct BufData { /* private fields */ }Expand description
§The databuf store kv data
use iii::BufData;
let mut cc = BufData::new();
cc.chgvalue("c3", "ccc3");
cc.chgvalue("c5", "5c");
if let Some(v) = cc.getvalue("c3"){
println!("K:{},V:{}","c3",v);
}
cc.save(None);Implementations§
Source§impl BufData
impl BufData
Sourcepub fn loadfromiii(filepath: &str) -> Result<Self, &'static str>
pub fn loadfromiii(filepath: &str) -> Result<Self, &'static str>
§load config file
use iii::BufData;
let mut cc = BufData::loadfromiii("default.iii");Sourcepub fn save(&self, newfilepath: Option<&str>) -> Result<(), &'static str>
pub fn save(&self, newfilepath: Option<&str>) -> Result<(), &'static str>
§save config to file
if newfile is None,use loaded file’s path to save
use iii::BufData;
if let Ok(mut cc) = BufData::loadfromiii("default.iii"){
cc.chgvalue("c3", "ccc3");
cc.chgvalue("c5", "5c");
if let Ok(_) = cc.save(None){
println!("file write success")
};
if let Ok(_) = cc.save(Some("file1.iii")){
println!("file1.iii write success")
}
}Sourcepub fn getvalue<T: FromStr>(&self, key: &str) -> Result<T, ()>
pub fn getvalue<T: FromStr>(&self, key: &str) -> Result<T, ()>
§read value from file by key
use iii::BufData;
if let Ok(cc) = BufData::loadfromiii("default.iii"){
cc.chgvalue("c2", "33");
cc.chgvalue("c4", &true.to_string());
let Ok(value) = cc.getvalue1::<u32>("c2").unwrap();
assert!(33==value);
let Ok(value) = cc.getvalue1::<bool>("c4").unwrap();
assert!(true==value);
};Trait Implementations§
Auto Trait Implementations§
impl Freeze for BufData
impl RefUnwindSafe for BufData
impl Send for BufData
impl Sync for BufData
impl Unpin for BufData
impl UnwindSafe for BufData
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