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.