Struct Object

Source
pub struct Object(/* private fields */);
Expand description

A type representing a JavaScript object.

Implementations§

Source§

impl Object

Source

pub fn len(&self) -> usize

Returns the number of elements in this particular object.

Source

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

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§

Source§

impl AsRef<Reference> for Object

Source§

fn as_ref(&self) -> &Reference

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Object

Source§

fn clone(&self) -> Object

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Object

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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

Source§

fn from(value: &'a BTreeMap<K, V>) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(value: &'a HashMap<K, V>) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(object: &'a Object) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(object: &'a Object) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(value: &'a mut BTreeMap<K, V>) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(value: &'a mut HashMap<K, V>) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(object: &'a mut Object) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(object: &'a mut Object) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(value: BTreeMap<K, V>) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(value: HashMap<K, V>) -> Self

Converts to this type from the input type.
Source§

impl From<Object> for BTreeMap<String, Value>

Source§

fn from(object: Object) -> Self

Converts to this type from the input type.
Source§

impl From<Object> for HashMap<String, Value>

Source§

fn from(object: Object) -> Self

Converts to this type from the input type.
Source§

impl From<Object> for Reference

Source§

fn from(value: Object) -> Self

Converts to this type from the input type.
Source§

impl InstanceOf for Object

Source§

fn instance_of(reference: &Reference) -> bool

Checks whenever a given Reference if of type Self.
Source§

impl PartialEq for Object

Source§

fn eq(&self, other: &Object) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ReferenceType for Object

Source§

unsafe fn from_reference_unchecked(reference: Reference) -> Self

Converts a given reference into a concrete reference-like wrapper. Doesn’t do any type checking; highly unsafe to use!
Source§

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

Source§

type Error = Void

The type returned in the event of a conversion error.
Source§

fn try_from(source: &'a BTreeMap<K, V>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

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

Source§

type Error = Void

The type returned in the event of a conversion error.
Source§

fn try_from(source: &'a HashMap<K, V>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'_r> TryFrom<&'_r Reference> for Object

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(reference: &Reference) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'_r> TryFrom<&'_r Value> for Object

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

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

Source§

type Error = Void

The type returned in the event of a conversion error.
Source§

fn try_from(source: &'a mut BTreeMap<K, V>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

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

Source§

type Error = Void

The type returned in the event of a conversion error.
Source§

fn try_from(source: &'a mut HashMap<K, V>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

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

Source§

type Error = Void

The type returned in the event of a conversion error.
Source§

fn try_from(source: BTreeMap<K, V>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

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

Source§

type Error = Void

The type returned in the event of a conversion error.
Source§

fn try_from(source: HashMap<K, V>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

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

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(object: Object) -> Result<Self, Self::Error>

Performs the conversion.
Source§

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

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(object: Object) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Object> for Reference

Source§

type Error = Void

The type returned in the event of a conversion error.
Source§

fn try_from(value: Object) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Reference> for Object

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(reference: Reference) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Object

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Object

Source§

impl JsSerialize for Object

Source§

impl StructuralPartialEq for Object

Auto Trait Implementations§

§

impl Freeze for Object

§

impl RefUnwindSafe for Object

§

impl Send for Object

§

impl Sync for Object

§

impl Unpin for Object

§

impl UnwindSafe for Object

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.