[][src]Struct stdweb::Object

pub struct Object(_);

A type representing a JavaScript object.

Methods

impl Object[src]

pub fn len(&self) -> usize[src]

Returns the number of elements in this particular object.

pub fn to_iter(&self) -> impl ExactSizeIterator<Item = (String, Value)>[src]

Retrieves an iterator over this object's keys and values.

When called, this method will pull all the objecy's keys and values from JavaScript, then return an iterator which accesses them in pairs.

Example:

use stdweb::{ js, unstable::TryInto, Object };

let obj: Object = js!( return { [1]: 2 } ).try_into()?;

let map: HashMap< i32, i32 > = obj
    .to_iter()
    .map( |(k, v)| Ok( ( k.parse()?, v.try_into()? ) ) )
    .collect::< Result< _, Box< dyn std::error::Error > > >()?;

assert_eq!( map[ &1 ], 2 );
panic!("ahhh");

Trait Implementations

impl JsSerialize for Object[src]

impl<K, V> TryFrom<BTreeMap<K, V>> for Object where
    K: AsRef<str>,
    V: JsSerialize
[src]

type Error = Void

The type returned in the event of a conversion error.

impl<'a, K, V> TryFrom<&'a BTreeMap<K, V>> for Object where
    K: AsRef<str>,
    V: JsSerialize
[src]

type Error = Void

The type returned in the event of a conversion error.

impl<'a, K, V> TryFrom<&'a mut BTreeMap<K, V>> for Object where
    K: AsRef<str>,
    V: JsSerialize
[src]

type Error = Void

The type returned in the event of a conversion error.

impl<K, V> TryFrom<HashMap<K, V, RandomState>> for Object where
    K: AsRef<str> + Eq + Hash,
    V: JsSerialize
[src]

type Error = Void

The type returned in the event of a conversion error.

impl<'a, K, V> TryFrom<&'a HashMap<K, V, RandomState>> for Object where
    K: AsRef<str> + Eq + Hash,
    V: JsSerialize
[src]

type Error = Void

The type returned in the event of a conversion error.

impl<'a, K, V> TryFrom<&'a mut HashMap<K, V, RandomState>> for Object where
    K: AsRef<str> + Eq + Hash,
    V: JsSerialize
[src]

type Error = Void

The type returned in the event of a conversion error.

impl TryFrom<Object> for Reference[src]

type Error = Void

The type returned in the event of a conversion error.

impl TryFrom<Reference> for Object[src]

type Error = ConversionError

The type returned in the event of a conversion error.

impl<'_r> TryFrom<&'_r Reference> for Object[src]

type Error = ConversionError

The type returned in the event of a conversion error.

impl TryFrom<Value> for Object[src]

type Error = ConversionError

The type returned in the event of a conversion error.

impl<'_r> TryFrom<&'_r Value> for Object[src]

type Error = ConversionError

The type returned in the event of a conversion error.

impl<E: Into<ConversionError>, V: TryFrom<Value, Error = E>> TryFrom<Object> for BTreeMap<String, V>[src]

type Error = ConversionError

The type returned in the event of a conversion error.

impl<E: Into<ConversionError>, V: TryFrom<Value, Error = E>> TryFrom<Object> for HashMap<String, V>[src]

type Error = ConversionError

The type returned in the event of a conversion error.

impl InstanceOf for Object[src]

impl ReferenceType for Object[src]

impl AsRef<Reference> for Object[src]

impl From<Object> for Reference[src]

impl From<Object> for BTreeMap<String, Value>[src]

impl<'a> From<&'a Object> for BTreeMap<String, Value>[src]

impl<'a> From<&'a mut Object> for BTreeMap<String, Value>[src]

impl From<Object> for HashMap<String, Value>[src]

impl<'a> From<&'a Object> for HashMap<String, Value>[src]

impl<'a> From<&'a mut Object> for HashMap<String, Value>[src]

impl<K: AsRef<str>, V: JsSerialize> From<BTreeMap<K, V>> for Object[src]

impl<'a, K, V> From<&'a BTreeMap<K, V>> for Object where
    K: AsRef<str>,
    V: JsSerialize
[src]

impl<'a, K, V> From<&'a mut BTreeMap<K, V>> for Object where
    K: AsRef<str>,
    V: JsSerialize
[src]

impl<K, V> From<HashMap<K, V, RandomState>> for Object where
    K: AsRef<str> + Hash + Eq,
    V: JsSerialize
[src]

impl<'a, K, V> From<&'a HashMap<K, V, RandomState>> for Object where
    K: AsRef<str> + Hash + Eq,
    V: JsSerialize
[src]

impl<'a, K: Hash + Eq, V> From<&'a mut HashMap<K, V, RandomState>> for Object where
    K: AsRef<str>,
    V: JsSerialize
[src]

impl Clone for Object[src]

impl Eq for Object[src]

impl PartialEq<Object> for Object[src]

impl Debug for Object[src]

Auto Trait Implementations

impl Send for Object

impl Sync for Object

impl Unpin for Object

impl UnwindSafe for Object

impl RefUnwindSafe for Object

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]