Trait ObjectExtension

Source
pub trait ObjectExtension {
Show 27 methods // Required methods fn get<T>(&self, prop: &str) -> Result<T, Error> where T: TryFrom<JsValue>, <T as TryFrom<JsValue>>::Error: Display; fn try_get<T>(&self, prop: &str) -> Result<Option<T>, Error> where T: TryFrom<JsValue>, <T as TryFrom<JsValue>>::Error: Display; fn cast_into<T>(&self, prop: &str) -> Result<T, Error> where T: TryCastFromJs, <T as TryCastFromJs>::Error: Display; fn cast_from<T>(&self, prop: &str) -> Result<Cast<'static, T>, Error> where T: TryCastFromJs, <T as TryCastFromJs>::Error: Display; fn try_cast_into<T>(&self, prop: &str) -> Result<Option<T>, Error> where T: TryCastFromJs, <T as TryCastFromJs>::Error: Display; fn try_cast_from<T>( &self, prop: &str, ) -> Result<Option<Cast<'static, T>>, Error> where T: TryCastFromJs, <T as TryCastFromJs>::Error: Display; fn get_value(&self, prop: &str) -> Result<JsValue, Error>; fn get_object(&self, prop: &str) -> Result<Object, Error>; fn try_get_object(&self, prop: &str) -> Result<Option<Object>, Error>; fn try_get_value(&self, prop: &str) -> Result<Option<JsValue>, Error>; fn get_string(&self, prop: &str) -> Result<String, Error>; fn try_get_string(&self, prop: &str) -> Result<Option<String>, Error>; fn get_u8(&self, prop: &str) -> Result<u8, Error>; fn get_u16(&self, prop: &str) -> Result<u16, Error>; fn get_u32(&self, prop: &str) -> Result<u32, Error>; fn get_u64(&self, prop: &str) -> Result<u64, Error>; fn get_f64(&self, prop: &str) -> Result<f64, Error>; fn get_bool(&self, prop: &str) -> Result<bool, Error>; fn try_get_bool(&self, prop: &str) -> Result<Option<bool>, Error>; fn get_vec(&self, prop: &str) -> Result<Vec<JsValue>, Error>; fn get_vec_u8(&self, prop: &str) -> Result<Vec<u8>, Error>; fn get_vec_u8_from_number_array(&self, prop: &str) -> Result<Vec<u8>, Error>; fn get_vec_u8_from_uint8_array(&self, prop: &str) -> Result<Vec<u8>, Error>; fn set(&self, prop: &str, value: &JsValue) -> Result<bool, Error>; fn set_vec(&self, prop: &str, values: &[JsValue]) -> Result<bool, Error>; fn set_properties(&self, props: &[(&str, &JsValue)]) -> Result<(), Error>; fn delete(&self, prop: &str) -> Result<bool, Error>;
}
Expand description

Custom trait implementing simplified property accessor functions for Object.

Required Methods§

Source

fn get<T>(&self, prop: &str) -> Result<T, Error>
where T: TryFrom<JsValue>, <T as TryFrom<JsValue>>::Error: Display,

Get a type that implements TryFrom<JsValue> from a property of the Object.

Source

fn try_get<T>(&self, prop: &str) -> Result<Option<T>, Error>
where T: TryFrom<JsValue>, <T as TryFrom<JsValue>>::Error: Display,

Try to get a type that implements TryFrom<JsValue> from a property of the Object. Returns Ok(None) if the property does not exist.

Source

fn cast_into<T>(&self, prop: &str) -> Result<T, Error>

Obtain a Cast from a property of the Object.

Source

fn cast_from<T>(&self, prop: &str) -> Result<Cast<'static, T>, Error>

Source

fn try_cast_into<T>(&self, prop: &str) -> Result<Option<T>, Error>

Try to obtain a Cast from a property of the Object. Returns Ok(None) if the property does not exist (null or undefined).

Source

fn try_cast_from<T>( &self, prop: &str, ) -> Result<Option<Cast<'static, T>>, Error>

Source

fn get_value(&self, prop: &str) -> Result<JsValue, Error>

Get JsValue property

Source

fn get_object(&self, prop: &str) -> Result<Object, Error>

Get Object property

Source

fn try_get_object(&self, prop: &str) -> Result<Option<Object>, Error>

Get Object property

Source

fn try_get_value(&self, prop: &str) -> Result<Option<JsValue>, Error>

Try Get JsValue property

Source

fn get_string(&self, prop: &str) -> Result<String, Error>

get String property

Source

fn try_get_string(&self, prop: &str) -> Result<Option<String>, Error>

get String property

Source

fn get_u8(&self, prop: &str) -> Result<u8, Error>

get Number property as u8

Source

fn get_u16(&self, prop: &str) -> Result<u16, Error>

get Number property as u16

Source

fn get_u32(&self, prop: &str) -> Result<u32, Error>

get Number property as u32

Source

fn get_u64(&self, prop: &str) -> Result<u64, Error>

get Number property as u64

Source

fn get_f64(&self, prop: &str) -> Result<f64, Error>

get Number property as f64

Source

fn get_bool(&self, prop: &str) -> Result<bool, Error>

get Boolean property as bool

Source

fn try_get_bool(&self, prop: &str) -> Result<Option<bool>, Error>

Source

fn get_vec(&self, prop: &str) -> Result<Vec<JsValue>, Error>

get property as Vec<JsValue>

Source

fn get_vec_u8(&self, prop: &str) -> Result<Vec<u8>, Error>

get Vec<u8> property from a hex string or an Array

Source

fn get_vec_u8_from_number_array(&self, prop: &str) -> Result<Vec<u8>, Error>

get Uint8Array property as Vec<u8>

Source

fn get_vec_u8_from_uint8_array(&self, prop: &str) -> Result<Vec<u8>, Error>

get Uint8Array property as Vec<u8>

Source

fn set(&self, prop: &str, value: &JsValue) -> Result<bool, Error>

set JsValue property

Source

fn set_vec(&self, prop: &str, values: &[JsValue]) -> Result<bool, Error>

set Array property from &[JsValue]

Source

fn set_properties(&self, props: &[(&str, &JsValue)]) -> Result<(), Error>

set multiple JsValue properties

Source

fn delete(&self, prop: &str) -> Result<bool, Error>

delete property

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl ObjectExtension for Object

Source§

fn get<T>(&self, prop: &str) -> Result<T, Error>
where T: TryFrom<JsValue>, <T as TryFrom<JsValue>>::Error: Display,

Source§

fn try_get<T>(&self, prop: &str) -> Result<Option<T>, Error>
where T: TryFrom<JsValue>, <T as TryFrom<JsValue>>::Error: Display,

Source§

fn cast_into<T>(&self, prop: &str) -> Result<T, Error>

Source§

fn cast_from<T>(&self, prop: &str) -> Result<Cast<'static, T>, Error>

Source§

fn try_cast_into<T>(&self, prop: &str) -> Result<Option<T>, Error>

Source§

fn try_cast_from<T>( &self, prop: &str, ) -> Result<Option<Cast<'static, T>>, Error>

Source§

fn get_value(&self, prop: &str) -> Result<JsValue, Error>

Source§

fn get_object(&self, prop: &str) -> Result<Object, Error>

Source§

fn try_get_object(&self, prop: &str) -> Result<Option<Object>, Error>

Source§

fn try_get_value(&self, prop: &str) -> Result<Option<JsValue>, Error>

Source§

fn get_string(&self, prop: &str) -> Result<String, Error>

Source§

fn try_get_string(&self, prop: &str) -> Result<Option<String>, Error>

Source§

fn get_bool(&self, prop: &str) -> Result<bool, Error>

Source§

fn try_get_bool(&self, prop: &str) -> Result<Option<bool>, Error>

Source§

fn get_u8(&self, prop: &str) -> Result<u8, Error>

Source§

fn get_u16(&self, prop: &str) -> Result<u16, Error>

Source§

fn get_u32(&self, prop: &str) -> Result<u32, Error>

Source§

fn get_u64(&self, prop: &str) -> Result<u64, Error>

Source§

fn get_vec(&self, prop: &str) -> Result<Vec<JsValue>, Error>

Source§

fn get_vec_u8(&self, prop: &str) -> Result<Vec<u8>, Error>

Source§

fn get_vec_u8_from_number_array(&self, prop: &str) -> Result<Vec<u8>, Error>

Source§

fn get_vec_u8_from_uint8_array(&self, prop: &str) -> Result<Vec<u8>, Error>

Source§

fn get_f64(&self, prop: &str) -> Result<f64, Error>

Source§

fn set(&self, prop: &str, value: &JsValue) -> Result<bool, Error>

Source§

fn set_vec(&self, prop: &str, values: &[JsValue]) -> Result<bool, Error>

Source§

fn set_properties(&self, props: &[(&str, &JsValue)]) -> Result<(), Error>

Source§

fn delete(&self, prop: &str) -> Result<bool, Error>

Implementors§