pub trait SerdeAPI: Serialize + for<'a> Deserialize<'a> {
// Provided methods
fn to_file(&self, filename: &str) -> Result<(), Error> { ... }
fn from_file(filename: &str) -> Result<Self, Error>
where Self: Sized + for<'de> 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§
Sourcefn from_file(filename: &str) -> Result<Self, Error>where
Self: Sized + for<'de> Deserialize<'de>,
fn from_file(filename: &str) -> Result<Self, Error>where
Self: Sized + for<'de> 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
: astr
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.
Sourcefn to_bincode(&self) -> Vec<u8> ⓘ
fn to_bincode(&self) -> Vec<u8> ⓘ
bincode serialization method.
Sourcefn from_bincode(encoded: &[u8]) -> Result<Self, Error>
fn from_bincode(encoded: &[u8]) -> Result<Self, Error>
bincode deserialization method.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.