neon::object

Struct PropOptions

source
pub struct PropOptions<'a, 'cx, O, K>
where O: Object, K: PropertyKey, 'cx: 'a,
{ /* private fields */ }
Expand description

A builder for accessing an object property.

The builder methods make it convenient to get and set properties as well as to bind and call methods.

let x: f64 = obj
    .prop(&mut cx, "x")
    .get()?;

obj.prop(&mut cx, "y")
    .set(x)?;

let s: String = obj.method(&mut cx, "toString")?.call()?;

Implementations§

source§

impl<'a, 'cx, O, K> PropOptions<'a, 'cx, O, K>
where O: Object, K: PropertyKey, 'cx: 'a,

source

pub fn this(&self) -> Handle<'cx, O>

Returns the original object from which the property was accessed.

source

pub fn prop(&mut self, key: K) -> &mut Self

Updates the property key.

This method is useful for chaining multiple property assignments:

let obj = cx.empty_object()
    .prop(&mut cx, "x")
    .set(1)?
    .prop("y")
    .set(2)?
    .prop("color")
    .set("blue")?
    .this();
source

pub fn get<R: TryFromJs<'cx>>(&mut self) -> NeonResult<R>

Gets the property from the object and attempts to convert it to a Rust value.

May throw an exception either during accessing the property or converting the result type.

source

pub fn set<V: TryIntoJs<'cx>>(&mut self, v: V) -> NeonResult<&mut Self>

Sets the property on the object to a value converted from Rust.

May throw an exception either during converting the value or setting the property.

source

pub fn set_with<R, F>(&mut self, f: F) -> NeonResult<&mut Self>
where R: TryIntoJs<'cx>, F: FnOnce(&mut Cx<'cx>) -> R,

Sets the property on the object to a value computed from a closure.

May throw an exception either during converting the value or setting the property.

source

pub fn bind(&'a mut self) -> NeonResult<BindOptions<'a, 'cx>>

Gets the property from the object as a method and binds this to the object.

May throw an exception when accessing the property.

Defers checking that the method is callable until call time.

Auto Trait Implementations§

§

impl<'a, 'cx, O, K> Freeze for PropOptions<'a, 'cx, O, K>
where K: Freeze, <O as TransparentNoCopyWrapper>::Inner: Freeze,

§

impl<'a, 'cx, O, K> RefUnwindSafe for PropOptions<'a, 'cx, O, K>
where K: RefUnwindSafe, <O as TransparentNoCopyWrapper>::Inner: RefUnwindSafe, O: RefUnwindSafe,

§

impl<'a, 'cx, O, K> !Send for PropOptions<'a, 'cx, O, K>

§

impl<'a, 'cx, O, K> !Sync for PropOptions<'a, 'cx, O, K>

§

impl<'a, 'cx, O, K> Unpin for PropOptions<'a, 'cx, O, K>
where K: Unpin, <O as TransparentNoCopyWrapper>::Inner: Unpin,

§

impl<'a, 'cx, O, K> !UnwindSafe for PropOptions<'a, 'cx, O, K>

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> 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.