pub struct Object { /* private fields */ }
Implementations§
Source§impl Object
impl Object
Sourcepub fn get<K: ToValue, V: FromValue>(&self, key: K) -> Result<V>
pub fn get<K: ToValue, V: FromValue>(&self, key: K) -> Result<V>
Get an object property value using the given key. Returns Value::Undefined
if no property
with the key exists.
Returns an error if ToValue::to_value
fails for the key or if the key value could not be
cast to a property key string.
Sourcepub fn set<K: ToValue, V: ToValue>(&self, key: K, value: V) -> Result<()>
pub fn set<K: ToValue, V: ToValue>(&self, key: K, value: V) -> Result<()>
Sets an object property using the given key and value.
Returns an error if ToValue::to_value
fails for either the key or the value or if the key
value could not be cast to a property key string.
Sourcepub fn remove<K: ToValue>(&self, key: K) -> Result<()>
pub fn remove<K: ToValue>(&self, key: K) -> Result<()>
Removes the property associated with the given key from the object. This function does nothing if the property does not exist.
Returns an error if ToValue::to_value
fails for the key or if the key value could not be
cast to a property key string.
Sourcepub fn has<K: ToValue>(&self, key: K) -> Result<bool>
pub fn has<K: ToValue>(&self, key: K) -> Result<bool>
Returns true
if the given key is a property of the object, false
otherwise.
Returns an error if ToValue::to_value
fails for the key or if the key value could not be
cast to a property key string.
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 keys(&self, include_inherited: bool) -> Result<Array>
pub fn keys(&self, include_inherited: bool) -> Result<Array>
Returns an array containing all of this object’s enumerable property keys. If
include_inherited
is false
, then only the object’s own enumerable properties will be
collected (similar to Object.getOwnPropertyNames
in Javascript). If include_inherited
is
true
, then the object’s own properties and the enumerable properties from its prototype
chain will be collected.
Sourcepub fn properties<K, V>(
self,
include_inherited: bool,
) -> Result<Properties<K, V>>
pub fn properties<K, V>( self, include_inherited: bool, ) -> Result<Properties<K, V>>
Converts the object into an iterator over the object’s keys and values, acting like a
for-in
loop.
For information on the include_inherited
argument, see Object::keys
.