Rof

Struct Rof 

Source
pub struct Rof { /* private fields */ }
Expand description

§Rof

A struct that contains an inner DataValue trait implementing object which contains utility functions for easy saving and loading that type to files, also is the backbone for the higher level RofCompat api.

A Rof DataValue does not strictly have to be a struct or enum, you can save and load any DataValue implementing type including

  • DataValueBool
  • DataValueChararacter
  • DataValueFloat
  • DataValueInteger
  • DataValueString
  • DataValueTuple (although this data value type does exist, the RofCompat API does not support types in it’s current state)
  • DataValueArray
  • DataValueHashmap
  • DataValueEnum
  • DataValueStruct

You cannot create your own DataValue types, as when deserializing a Rof from a string, a function named data_value_from_string checks the string against every DataValue type until it finds a type that when deserialized doesn’t return None. As this function only checks against inbuilt types that it knows about, you cannot create your own as they would not get deserialized.

Implementations§

Source§

impl Rof

Source

pub fn new(inner: Box<dyn DataValue>) -> Self

Create a Rof from an inner DataValue implementing type

Source

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

§Serialize

Serialize the Rof to a string

§Argmuents
  • pretty_print - A bool which when set to true adds unneccesary white space, tabs and newlines to the serialized output that will not change the data, but will make the output string more human-readable if saved to a file.
Source

pub fn deserialize(serialized_rof: &str) -> Self

§Deserialize

Deserialize a string to a Rof

§Arguments
  • serialized_rof - A string slice that represents a DataValue implementing data type in string form.

If this function fails to to deserialize the type, it will default to returning DataValueEnum::none()

Source

pub fn load_from_file(file_path: &str) -> Self

§Load From File

Loads a Rof object from file by loading the file as a string and using that on the deserialize function to convert that to a Rof

§Arguments
  • file_path - A string slice representing the load file path

If the function fails in any way, DataValueEnum::none() will be returned

Source

pub fn save_to_file( &self, file_path: &str, pretty_print: bool, ) -> Result<(), ()>

§Save To File

Saves the inner ``DataValueimplementing value of theRofto a file using the object on theserialize``` function to serialize the object to a string

Will return an error if the file saving fails

§Arguments
  • file_path - A string slice representing the save file path
  • pretty_print - A bool which when set to true adds unneccesary white space, tabs and newlines to the serialized output that will not change the data, but will make the output file more human-readable.
Source

pub fn get_object(&self) -> Box<dyn DataValue>

§Get Object

Returns an immutable clone of the inner DataValue implementing object which this Rof contains.

It is important to note that the returned value is immutable meaning you cannot get the inner value, modify something and run the serialize or save_to_file function on the same Rof, as the inner value of the Rof will not have changed. You will need to create a new Rof with the newly modified DataValue implementing object for the changes to be reflected for the file.

Trait Implementations§

Source§

impl Debug for Rof

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Rof

§

impl !RefUnwindSafe for Rof

§

impl !Send for Rof

§

impl !Sync for Rof

§

impl Unpin for Rof

§

impl !UnwindSafe for Rof

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.