pub struct Object<'ducc>(/* private fields */);Expand description
Reference to a JavaScript object (guaranteed to not be an array or function).
Implementations§
Source§impl<'ducc> Object<'ducc>
impl<'ducc> Object<'ducc>
Sourcepub fn get<K: ToValue<'ducc>, V: FromValue<'ducc>>(&self, key: K) -> Result<V>
pub fn get<K: ToValue<'ducc>, V: FromValue<'ducc>>(&self, key: K) -> Result<V>
Get an object property value using the given key. Returns Value::Undefined if no property
with the key exists.
§Errors
This function returns an error if:
ToValue::to_valuefails for the key- The
ToPropertyKeyimplementation for the key fails
Sourcepub fn set<K: ToValue<'ducc>, V: ToValue<'ducc>>(
&self,
key: K,
value: V,
) -> Result<()>
pub fn set<K: ToValue<'ducc>, V: ToValue<'ducc>>( &self, key: K, value: V, ) -> Result<()>
Sets an object property using the given key and value.
§Errors
This function returns an error if:
ToValue::to_valuefails for either the key or the value- The
ToPropertyKeyimplementation for the key fails
Sourcepub fn remove<K: ToValue<'ducc>>(&self, key: K) -> Result<()>
pub fn remove<K: ToValue<'ducc>>(&self, key: K) -> Result<()>
Removes the given key from the object. This function does nothing if the property does not exist.
§Errors
This function returns an error if:
ToValue::to_valuefails for the key- The
ToPropertyKeyimplementation for the key fails
Sourcepub fn contains_key<K: ToValue<'ducc>>(&self, key: K) -> Result<bool>
pub fn contains_key<K: ToValue<'ducc>>(&self, key: K) -> Result<bool>
Returns true if the given key is a property of the object, false otherwise.
§Errors
This function returns an error if:
ToValue::to_valuefails for the key- The
ToPropertyKeyimplementation for the key fails
Sourcepub fn len(&self) -> Result<usize>
pub fn len(&self) -> Result<usize>
Returns the number of elements in the object using the calculation
Math.floor(ToNumber(obj.length)). This function can return an error if the ToNumber
implementation fails or if the length getter fails. Returns Ok(0) if the calculation
returns a number (a floating point in JavaScript land) outside of the range of usize.
Sourcepub fn call_prop<K, A, R>(&self, key: K, args: A) -> Result<R>
pub fn call_prop<K, A, R>(&self, key: K, args: A) -> Result<R>
Calls the function at the key with the given arguments, with this set to the object.
Returns an error if the value at the key is not a function.
Sourcepub fn properties<K: FromValue<'ducc>, V: FromValue<'ducc>>(
self,
) -> Properties<'ducc, K, V> ⓘ
pub fn properties<K: FromValue<'ducc>, V: FromValue<'ducc>>( self, ) -> Properties<'ducc, K, V> ⓘ
Returns an iterator over the object’s keys and values, acting like a for-in loop: own and
inherited enumerable properties are included, and enumeration order follows the ES2015
OwnPropertyKeys enumeration order, applied for each inheritance level.