BufData

Struct BufData 

Source
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

Source

pub fn new() -> Self

Create a empty data squence in memory

Source

pub fn loadfromiii(filepath: &str) -> Result<Self, &'static str>

§load config file
use iii::BufData;
let mut cc = BufData::loadfromiii("default.iii");
Source

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")
    }
}
Source

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);
};
Source

pub fn chgvalue<T: Display>(&mut self, key: &str, value: T)

§write value or change value
use iii::BufData;
if let Ok(mut cc) = BufData::loadfromiii("default.iii"){
    cc.chgvalue("c3", "ccc3");
    cc.chgvalue("c5", 233);
    if let Ok(_) = cc.save(None){
        println!("file write success")
    };
};

Trait Implementations§

Source§

impl Default for BufData

Source§

fn default() -> BufData

Returns the “default value” for a type. 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.