Struct iii::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: &'static 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<&'static 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(&self, key: &'static str) -> Option<String>

read value from file by key
use iii::BufData;
if let Ok(cc) = BufData::loadfromiii("default.iii"){
    if let Some(v) = cc.getvalue("c2"){
        println!("K:{},V:{}","c2",v);
    }
    if let Some(v) = cc.getvalue("c5"){
        println!("K:{},V:{}","c5",v);
    }
};
source

pub fn chgvalue(&mut self, key: &'static str, value: &str)

write value or change value
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")
    };
};

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.