Trait altrios_core::traits::SerdeAPI
source · pub trait SerdeAPI: Serialize + for<'a> Deserialize<'a> {
const ACCEPTED_BYTE_FORMATS: &'static [&'static str] = _;
const ACCEPTED_STR_FORMATS: &'static [&'static str] = _;
// Provided methods
fn init(&mut self) -> Result<()> { ... }
fn to_file<P: AsRef<Path>>(&self, filepath: P) -> Result<()> { ... }
fn from_file<P: AsRef<Path>>(filepath: P) -> Result<Self> { ... }
fn to_str(&self, format: &str) -> Result<String> { ... }
fn from_str<S: AsRef<str>>(contents: S, format: &str) -> Result<Self> { ... }
fn from_reader<R>(rdr: R, format: &str) -> Result<Self>
where R: Read { ... }
fn to_json(&self) -> Result<String> { ... }
fn from_json<S: AsRef<str>>(json_str: S) -> Result<Self> { ... }
fn to_yaml(&self) -> Result<String> { ... }
fn from_yaml<S: AsRef<str>>(yaml_str: S) -> Result<Self> { ... }
fn to_bincode(&self) -> Result<Vec<u8>> { ... }
fn from_bincode(encoded: &[u8]) -> Result<Self> { ... }
}
Provided Associated Constants§
const ACCEPTED_BYTE_FORMATS: &'static [&'static str] = _
const ACCEPTED_STR_FORMATS: &'static [&'static str] = _
Provided Methods§
sourcefn to_file<P: AsRef<Path>>(&self, filepath: P) -> Result<()>
fn to_file<P: AsRef<Path>>(&self, filepath: P) -> Result<()>
Write (serialize) an object to a file.
Supported file extensions are listed in ACCEPTED_BYTE_FORMATS
.
Creates a new file if it does not already exist, otherwise truncates the existing file.
§Arguments
filepath
- The filepath at which to write the object
sourcefn from_file<P: AsRef<Path>>(filepath: P) -> Result<Self>
fn from_file<P: AsRef<Path>>(filepath: P) -> Result<Self>
Read (deserialize) an object from a file.
Supported file extensions are listed in ACCEPTED_BYTE_FORMATS
.
§Arguments:
filepath
: The filepath from which to read the object
sourcefn to_str(&self, format: &str) -> Result<String>
fn to_str(&self, format: &str) -> Result<String>
Write (serialize) an object into a string
§Arguments:
format
- The target format, any of those listed inACCEPTED_STR_FORMATS
sourcefn from_str<S: AsRef<str>>(contents: S, format: &str) -> Result<Self>
fn from_str<S: AsRef<str>>(contents: S, format: &str) -> Result<Self>
Read (deserialize) an object from a string
§Arguments:
contents
- The string containing the object dataformat
- The source format, any of those listed inACCEPTED_STR_FORMATS
sourcefn from_reader<R>(rdr: R, format: &str) -> Result<Self>where
R: Read,
fn from_reader<R>(rdr: R, format: &str) -> Result<Self>where
R: Read,
Deserialize an object from anything that implements std::io::Read
§Arguments:
rdr
- The reader from which to read object dataformat
- The source format, any of those listed inACCEPTED_BYTE_FORMATS
sourcefn from_json<S: AsRef<str>>(json_str: S) -> Result<Self>
fn from_json<S: AsRef<str>>(json_str: S) -> Result<Self>
Read (deserialize) an object to a JSON string
§Arguments
json_str
- JSON-formatted string to deserialize from
sourcefn from_yaml<S: AsRef<str>>(yaml_str: S) -> Result<Self>
fn from_yaml<S: AsRef<str>>(yaml_str: S) -> Result<Self>
Read (deserialize) an object from a YAML string
§Arguments
yaml_str
- YAML-formatted string to deserialize from
sourcefn to_bincode(&self) -> Result<Vec<u8>>
fn to_bincode(&self) -> Result<Vec<u8>>
Write (serialize) an object to bincode-encoded bytes
sourcefn from_bincode(encoded: &[u8]) -> Result<Self>
fn from_bincode(encoded: &[u8]) -> Result<Self>
Read (deserialize) an object from bincode-encoded bytes
§Arguments
encoded
- Encoded bytes to deserialize from
Object Safety§
This trait is not object safe.