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
DataValueBoolDataValueChararacterDataValueFloatDataValueIntegerDataValueStringDataValueTuple(although this data value type does exist, the RofCompat API does not support types in it’s current state)DataValueArrayDataValueHashmapDataValueEnumDataValueStruct
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
impl Rof
Sourcepub fn new(inner: Box<dyn DataValue>) -> Self
pub fn new(inner: Box<dyn DataValue>) -> Self
Create a Rof from an inner DataValue implementing type
Sourcepub fn deserialize(serialized_rof: &str) -> Self
pub fn deserialize(serialized_rof: &str) -> Self
Sourcepub fn load_from_file(file_path: &str) -> Self
pub fn load_from_file(file_path: &str) -> Self
Sourcepub fn save_to_file(
&self,
file_path: &str,
pretty_print: bool,
) -> Result<(), ()>
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 pathpretty_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.
Sourcepub fn get_object(&self) -> Box<dyn DataValue>
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.