Skip to main content

ConfigSerializable

Trait ConfigSerializable 

Source
pub trait ConfigSerializable {
    // Required methods
    fn to_json(&self) -> Result<String>;
    fn from_json(json: &str) -> Result<Self>
       where Self: Sized;

    // Provided methods
    fn save_to_file(&self, path: &Path) -> Result<()> { ... }
    fn load_from_file(path: &Path) -> Result<Self>
       where Self: Sized { ... }
}
Expand description

Trait for objects that can be serialized as configuration

Required Methods§

Source

fn to_json(&self) -> Result<String>

Serialize to JSON string

Source

fn from_json(json: &str) -> Result<Self>
where Self: Sized,

Deserialize from JSON string

Provided Methods§

Source

fn save_to_file(&self, path: &Path) -> Result<()>

Save to file

Source

fn load_from_file(path: &Path) -> Result<Self>
where Self: Sized,

Load from file

Implementors§

Source§

impl<T> ConfigSerializable for T
where T: Serialize + for<'de> Deserialize<'de>,

Default implementation for types that implement Serialize + DeserializeOwned