pub struct Obj { /* private fields */ }
Expand description
Obj
struct.
Implementations§
Source§impl Obj
impl Obj
Sourcepub fn from_map(obj_map: HashMap<String, Value>) -> OverResult<Obj>
pub fn from_map(obj_map: HashMap<String, Value>) -> OverResult<Obj>
Returns a new Obj
created from the given HashMap
.
Returns an error if the map contains an invalid field name. A valid field name must start with an alphabetic character or ‘’ and subsequent characters must be alphabetic, numeric, or ‘’.
Sourcepub fn from_map_with_parent(
obj_map: HashMap<String, Value>,
parent: Obj,
) -> OverResult<Obj>
pub fn from_map_with_parent( obj_map: HashMap<String, Value>, parent: Obj, ) -> OverResult<Obj>
Returns a new Obj
created from the given HashMap
with given parent
.
Returns an error if the map contains an invalid field name.
See from_map
for more details.
Sourcepub fn from_map_unchecked(obj_map: HashMap<String, Value>) -> Obj
pub fn from_map_unchecked(obj_map: HashMap<String, Value>) -> Obj
Returns a new Obj
created from the given HashMap
.
It is faster than the safe version, from_map
, if you know every field has a valid name.
You can check ahead of time whether a field is valid with is_valid_field
.
See from_map
for more details.
Sourcepub fn from_map_with_parent_unchecked(
obj_map: HashMap<String, Value>,
parent: Obj,
) -> Obj
pub fn from_map_with_parent_unchecked( obj_map: HashMap<String, Value>, parent: Obj, ) -> Obj
Returns a new Obj
created from the given HashMap
with given parent
.
It is faster than the safe version, from_map_with_parent
, if you know every field has
a valid name. You can check ahead of time whether a field is valid with is_valid_field
.
See from_map
for more details.
Sourcepub fn id(&self) -> usize
pub fn id(&self) -> usize
Returns the ID of this Obj
.
Every Obj
is assigned its own globally unique ID. IDs are generated incrementally,
starting at 0 for the first Obj
created.
§Notes
The ID is ignored when testing Obj
equality.
Sourcepub fn map_ref(&self) -> &HashMap<String, Value>
pub fn map_ref(&self) -> &HashMap<String, Value>
Returns a reference to the inner map of this Obj
.
Sourcepub fn from_file(path: &str) -> OverResult<Obj>
pub fn from_file(path: &str) -> OverResult<Obj>
Returns a new Obj
loaded from a file.
Sourcepub fn write_to_file(&self, path: &str) -> OverResult<()>
pub fn write_to_file(&self, path: &str) -> OverResult<()>
Writes this Obj
to given file in .over
representation.
§Notes
Note that the fields of the Obj
will be output in an unpredictable order.
Also note that shorthand in the original file, including variables and file includes,
is not preserved when parsing the file, and will not appear when writing to another file.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of fields for this Obj
(parent fields not included).
Sourcepub fn ptr_eq(&self, other: &Self) -> bool
pub fn ptr_eq(&self, other: &Self) -> bool
Returns whether self
and other
point to the same data.
Sourcepub fn get_with_source(&self, field: &str) -> Option<(Value, Obj)>
pub fn get_with_source(&self, field: &str) -> Option<(Value, Obj)>
Gets the Value
associated with field
and the Obj
where it was found (either self
or
one of its parents).
Sourcepub fn get_bool(&self, field: &str) -> OverResult<bool>
pub fn get_bool(&self, field: &str) -> OverResult<bool>
Returns the bool
found at field
. Returns an error if the field was not found or if the Value
at field
is not Bool
.
Sourcepub fn get_int(&self, field: &str) -> OverResult<BigInt>
pub fn get_int(&self, field: &str) -> OverResult<BigInt>
Returns the BigInt
found at field
. Returns an error if the field was not found or if the Value
at field
is not Int
.
Sourcepub fn get_frac(&self, field: &str) -> OverResult<BigRational>
pub fn get_frac(&self, field: &str) -> OverResult<BigRational>
Returns the BigRational
found at field
. Returns an error if the field was not found or if the Value
at field
is not Frac
.
Sourcepub fn get_char(&self, field: &str) -> OverResult<char>
pub fn get_char(&self, field: &str) -> OverResult<char>
Returns the char
found at field
. Returns an error if the field was not found or if the Value
at field
is not Char
.
Sourcepub fn get_str(&self, field: &str) -> OverResult<String>
pub fn get_str(&self, field: &str) -> OverResult<String>
Returns the String
found at field
. Returns an error if the field was not found or if the Value
at field
is not Str
.
Sourcepub fn get_arr(&self, field: &str) -> OverResult<Arr>
pub fn get_arr(&self, field: &str) -> OverResult<Arr>
Returns the Arr
found at field
. Returns an error if the field was not found or if the Value
at field
is not Arr
.
Sourcepub fn get_tup(&self, field: &str) -> OverResult<Tup>
pub fn get_tup(&self, field: &str) -> OverResult<Tup>
Returns the Tup
found at field
. Returns an error if the field was not found or if the Value
at field
is not Tup
.
Sourcepub fn get_obj(&self, field: &str) -> OverResult<Obj>
pub fn get_obj(&self, field: &str) -> OverResult<Obj>
Returns the Obj
found at field
. Returns an error if the field was not found or if the Value
at field
is not Obj
.
Sourcepub fn has_parent(&self) -> bool
pub fn has_parent(&self) -> bool
Returns whether this Obj
has a parent.
Sourcepub fn get_parent(&self) -> Option<Obj>
pub fn get_parent(&self) -> Option<Obj>
Returns the parent for this Obj
.
Sourcepub fn is_valid_field(field: &str) -> bool
pub fn is_valid_field(field: &str) -> bool
Returns true if field
is a valid field name for an Obj
.
The first character must be alphabetic or ‘’. Subsequent characters are allowed to be alphabetic, digits, or ‘’.
Sourcepub fn is_valid_field_char(ch: char, first: bool) -> bool
pub fn is_valid_field_char(ch: char, first: bool) -> bool
Returns true if the given char is valid for a field, depending on whether it is the first char or not.
See is_valid_field
for more details.
Sourcepub fn keys(&self) -> Keys<'_, String, Value>
pub fn keys(&self) -> Keys<'_, String, Value>
An iterator visiting all fields (keys) in arbitrary order.