Struct arithmetic_eval::Object
source · pub struct Object<T> { /* private fields */ }
Expand description
Object with zero or more named fields.
An object functions similarly to a HashMap
with String
keys and Value
values. It allows iteration over name-value pairs, random access by field name,
inserting / removing fields etc.
§Examples
let mut obj = Object::<u32>::default();
obj.insert("field", Value::Prim(0));
obj.insert("other_field", Value::Bool(false));
assert_eq!(obj.len(), 2);
assert_eq!(obj["field"].value_type(), ValueType::Prim);
assert!(obj.iter().all(|(_, val)| !val.is_void()));
// `Object` implements `FromIterator` / `Extend`.
let fields = vec![
("third", Value::Prim(3)),
("fourth", Value::native_fn(fns::Assert)),
];
let mut other_obj: Object<u32> = fields.into_iter().collect();
other_obj.extend(obj);
assert_eq!(other_obj.len(), 4);
Implementations§
source§impl<T> Object<T>
impl<T> Object<T>
sourcepub fn just(field_name: impl Into<String>, value: Value<T>) -> Self
pub fn just(field_name: impl Into<String>, value: Value<T>) -> Self
Creates an object with a single field.
sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &Value<T>)> + '_
pub fn iter(&self) -> impl Iterator<Item = (&str, &Value<T>)> + '_
Iterates over name-value pairs for all fields defined in this object.
sourcepub fn field_names(&self) -> impl Iterator<Item = &str> + '_
pub fn field_names(&self) -> impl Iterator<Item = &str> + '_
Iterates over field names.
sourcepub fn get(&self, field_name: &str) -> Option<&Value<T>>
pub fn get(&self, field_name: &str) -> Option<&Value<T>>
Returns the value of a field with the specified name, or None
if this object
does not contain such a field.
sourcepub fn contains_field(&self, field_name: &str) -> bool
pub fn contains_field(&self, field_name: &str) -> bool
Checks whether this object has a field with the specified name.
Trait Implementations§
source§impl<T, S, V> Extend<(S, V)> for Object<T>
impl<T, S, V> Extend<(S, V)> for Object<T>
source§fn extend<I: IntoIterator<Item = (S, V)>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = (S, V)>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
source§impl<T, S, V> FromIterator<(S, V)> for Object<T>
impl<T, S, V> FromIterator<(S, V)> for Object<T>
source§impl<T> IntoEvalResult<T> for Object<T>
impl<T> IntoEvalResult<T> for Object<T>
source§fn into_eval_result(self) -> Result<Value<T>, ErrorOutput>
fn into_eval_result(self) -> Result<Value<T>, ErrorOutput>
Performs the conversion.
source§impl<'r, T> IntoIterator for &'r Object<T>
impl<'r, T> IntoIterator for &'r Object<T>
source§impl<T> IntoIterator for Object<T>
impl<T> IntoIterator for Object<T>
source§impl<T: PartialEq> PartialEq for Object<T>
impl<T: PartialEq> PartialEq for Object<T>
source§impl<T> TryFromValue<T> for Object<T>
impl<T> TryFromValue<T> for Object<T>
source§fn try_from_value(value: Value<T>) -> Result<Self, FromValueError>
fn try_from_value(value: Value<T>) -> Result<Self, FromValueError>
Attempts to convert
value
to a type supported by the function.impl<T> StructuralPartialEq for Object<T>
Auto Trait Implementations§
impl<T> Freeze for Object<T>
impl<T> !RefUnwindSafe for Object<T>
impl<T> !Send for Object<T>
impl<T> !Sync for Object<T>
impl<T> Unpin for Object<T>where
T: Unpin,
impl<T> !UnwindSafe for Object<T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)