Trait ReadWrite

Source
pub trait ReadWrite: Serialize + DeserializeOwned {
    // Required method
    fn create_null() -> Self;

    // Provided methods
    fn save_as<T: AsRef<str>>(&self, file_path: T) -> Result<(), LadduError> { ... }
    fn load_from<T: AsRef<str>>(file_path: T) -> Result<Self, LadduError> { ... }
}
Expand description

A trait which allows structs with Serialize and Deserialize to be written and read from files with a certain set of types/extensions.

Currently, Python’s pickle format is supported supported, since it’s an easy-to-parse standard that supports floating point values better that JSON or TOML

Required Methods§

Source

fn create_null() -> Self

Create a null version of the object which acts as a shell into which Python’s pickle module can load data. This generally shouldn’t be used to construct the struct in regular code.

Provided Methods§

Source

fn save_as<T: AsRef<str>>(&self, file_path: T) -> Result<(), LadduError>

Save a serde-object to a file path, using the extension to determine the file format

Source

fn load_from<T: AsRef<str>>(file_path: T) -> Result<Self, LadduError>

Load a serde-object from a file path, using the extension to determine the file format

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.

Implementations on Foreign Types§

Source§

impl ReadWrite for Point

Source§

fn create_null() -> Self

Source§

impl ReadWrite for Particle

Source§

fn create_null() -> Self

Source§

impl ReadWrite for Swarm

Source§

fn create_null() -> Self

Implementors§