pub trait SerdeAPI: Serialize + for<'a> Deserialize<'a> {
    // Provided methods
    fn init(&mut self) -> Result<()> { ... }
    fn to_file(&self, filename: &str) -> Result<(), Error> { ... }
    fn from_file(filename: &str) -> Result<Self, Error>
       where for<'de> Self: Sized + Deserialize<'de> { ... }
    fn to_json(&self) -> String { ... }
    fn from_json(json_str: &str) -> Result<Self, Error> { ... }
    fn to_yaml(&self) -> String { ... }
    fn from_yaml(yaml_str: &str) -> Result<Self, Error> { ... }
    fn to_bincode(&self) -> Vec<u8> { ... }
    fn from_bincode(encoded: &[u8]) -> Result<Self, Error> { ... }
}

Provided Methods§

source

fn init(&mut self) -> Result<()>

runs any initialization steps that might be needed

source

fn to_file(&self, filename: &str) -> Result<(), Error>

Save current data structure to file. Method adaptively calls serialization methods dependent on the suffix of the file given as str.

Argument:
  • filename: a str storing the targeted file name. Currently .json and .yaml suffixes are supported
Returns:

A Rust Result

source

fn from_file(filename: &str) -> Result<Self, Error>where for<'de> Self: Sized + Deserialize<'de>,

Read from file and return instantiated struct. Method adaptively calls deserialization methods dependent on the suffix of the file name given as str. Function returns a dynamic Error Result if it fails.

Argument:
  • filename: a str storing the targeted file name. Currently .json and .yaml suffixes are supported
Returns:

A Rust Result wrapping data structure if method is called successfully; otherwise a dynamic Error.

source

fn to_json(&self) -> String

json serialization method.

source

fn from_json(json_str: &str) -> Result<Self, Error>

json deserialization method.

source

fn to_yaml(&self) -> String

yaml serialization method.

source

fn from_yaml(yaml_str: &str) -> Result<Self, Error>

yaml deserialization method.

source

fn to_bincode(&self) -> Vec<u8>

bincode serialization method.

source

fn from_bincode(encoded: &[u8]) -> Result<Self, Error>

bincode deserialization method.

Implementors§