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,
impl<'a, 'cx, O, K> PropOptions<'a, 'cx, O, K>where
O: Object,
K: PropertyKey,
'cx: 'a,
Sourcepub fn this(&self) -> Handle<'cx, O>
pub fn this(&self) -> Handle<'cx, O>
Returns the original object from which the property was accessed.
Sourcepub fn prop(&mut self, key: K) -> &mut Self
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();
Sourcepub fn get<R: TryFromJs<'cx>>(&mut self) -> NeonResult<R>
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.
Sourcepub fn set<V: TryIntoJs<'cx>>(&mut self, v: V) -> NeonResult<&mut Self>
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.
Sourcepub fn set_with<R, F>(&mut self, f: F) -> NeonResult<&mut Self>
pub fn set_with<R, F>(&mut self, f: F) -> NeonResult<&mut Self>
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.
Sourcepub fn bind(&'a mut self) -> NeonResult<BindOptions<'a, 'cx>>
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>
impl<'a, 'cx, O, K> RefUnwindSafe for PropOptions<'a, 'cx, O, K>
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>
impl<'a, 'cx, O, K> !UnwindSafe for PropOptions<'a, 'cx, O, K>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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