RofCompat

Trait RofCompat 

Source
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§

Source

fn serialize(&self) -> Box<dyn DataValue>

§Serialize

Serialize RofCompat implementing object to a DataValue implementing object.

§Example
fn serialize(&self) -> Box<dyn DataValue> {
    Box::new(DataValueInteger::U32(
        65536 * (self.r as u32) + 256 * (self.g as u32) + (self.b as u32),
    ))
}
Source

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§

Source

fn serialize_to_string(&self, pretty_print: bool) -> String

Source

fn deserialize_from_string(serialized_rof: &str) -> Self

Source

fn as_rof(&self) -> Rof

§As Rof

Returns a new Rof created from itself’s serialized value

Source

fn load_from_file(file_path: &str) -> Self

Source

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.

Implementations on Foreign Types§

Source§

impl RofCompat for bool

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Source§

impl RofCompat for char

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Source§

impl RofCompat for f32

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Source§

impl RofCompat for f64

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Source§

impl RofCompat for i8

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Source§

impl RofCompat for i16

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Source§

impl RofCompat for i32

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Source§

impl RofCompat for i64

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Source§

impl RofCompat for i128

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Source§

impl RofCompat for isize

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Source§

impl RofCompat for u8

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Source§

impl RofCompat for u16

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Source§

impl RofCompat for u32

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Source§

impl RofCompat for u64

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Source§

impl RofCompat for u128

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Source§

impl RofCompat for usize

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Source§

impl RofCompat for String

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Source§

impl<K: RofCompat + Hash + Eq, V: RofCompat> RofCompat for HashMap<K, V>

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Source§

impl<T: RofCompat> RofCompat for Option<T>

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Source§

impl<T: RofCompat> RofCompat for Vec<T>

Source§

fn serialize(&self) -> Box<dyn DataValue>

Source§

fn deserialize(rof_object: Box<dyn DataValue>) -> Self

Implementors§