pub trait RofCompat: Default {
// Required methods
fn serialize(&self) -> Box<dyn DataValue>;
fn deserialize(rof_object: Box<dyn DataValue>) -> Self;
// Provided methods
fn serialize_to_string(&self, pretty_print: bool) -> String { ... }
fn deserialize_from_string(serialized_rof: &str) -> Self { ... }
fn as_rof(&self) -> Rof { ... }
fn load_from_file(file_path: &str) -> Self { ... }
fn save_to_file(
&self,
file_path: &str,
pretty_print: bool,
) -> Result<(), ()> { ... }
}Expand description
§Rof Compatible
A trait that enables a high level abstraction from the low level system that allows serializing and deserializing any RofCompat implementing type to string.
Using the RofCompat derive macro, you can automatically implement the RofCompat trait on any struct or enum in most situations (refer to docs for more information).
In order to manually implement RofCompat for any type, the serialize and deserialize methods only have to be implemented, as the other functions are only utility functions based on those two simple methods.
Required Methods§
Sourcefn deserialize(rof_object: Box<dyn DataValue>) -> Self
fn deserialize(rof_object: Box<dyn DataValue>) -> Self
§Deserialize
Deserialize a DataValue implementing (not string) to itself.
§Example
fn deserialize(rof_object: Box<dyn DataValue>) -> Self {
let color_int: u32 = rof_object.as_u32();
Self {
r: (color_int % 16_777_216 / 65_536) as u8,
g: (color_int % 65_536 / 256) as u8,
b: (color_int % 256) as u8,
}
}Provided Methods§
fn serialize_to_string(&self, pretty_print: bool) -> String
fn deserialize_from_string(serialized_rof: &str) -> Self
fn load_from_file(file_path: &str) -> Self
fn save_to_file(&self, file_path: &str, pretty_print: bool) -> Result<(), ()>
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.