Struct Obj

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

Obj struct.

Implementations§

Source§

impl Obj

Source

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 ‘’.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn map_ref(&self) -> &HashMap<String, Value>

Returns a reference to the inner map of this Obj.

Source

pub fn from_file(path: &str) -> OverResult<Obj>

Returns a new Obj loaded from a file.

Source

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.

Source

pub fn write_str(&self) -> String

Writes this Obj to a String.

§Notes

See write_to_file.

Source

pub fn with_each<F>(&self, f: F)
where F: FnMut(&String, &Value),

Iterates over each (String, Value) pair in self, applying f.

Source

pub fn len(&self) -> usize

Returns the number of fields for this Obj (parent fields not included).

Source

pub fn is_empty(&self) -> bool

Returns whether this Obj is empty.

Source

pub fn ptr_eq(&self, other: &Self) -> bool

Returns whether self and other point to the same data.

Source

pub fn contains(&self, field: &str) -> bool

Returns true if this Obj contains field.

Source

pub fn get(&self, field: &str) -> Option<Value>

Gets the Value associated with field.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn has_parent(&self) -> bool

Returns whether this Obj has a parent.

Source

pub fn get_parent(&self) -> Option<Obj>

Returns the parent for this Obj.

Source

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 ‘’.

Source

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.

Source

pub fn keys(&self) -> Keys<'_, String, Value>

An iterator visiting all fields (keys) in arbitrary order.

Source

pub fn values(&self) -> Values<'_, String, Value>

An iterator visiting all values in arbitrary order.

Source

pub fn iter(&self) -> Iter<'_, String, Value>

An iterator visiting all field-value pairs in arbitrary order.

Trait Implementations§

Source§

impl Clone for Obj

Source§

fn clone(&self) -> Obj

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Obj

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Obj

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Obj

Source§

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

Formats the value using the given formatter. Read more
Source§

impl From<Obj> for Value

Source§

fn from(inner: Obj) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Obj

Source§

type Err = OverError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq<Obj> for Value

Source§

fn eq(&self, other: &Obj) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Value> for Obj

Source§

fn eq(&self, other: &Value) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for Obj

For two Objs to be equal, the following two checks must pass:

  1. If either Obj has a parent, then both must have parents and the parents must be equal.
  2. The two Objs must have all the same fields pointing to the same values.
Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl Freeze for Obj

§

impl RefUnwindSafe for Obj

§

impl Send for Obj

§

impl Sync for Obj

§

impl Unpin for Obj

§

impl UnwindSafe for Obj

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.