Struct neon::handle::Handle

source ·
pub struct Handle<'a, V: Value + 'a> { /* private fields */ }
Expand description

A handle to a JavaScript value that is owned by the JavaScript engine.

Implementations§

source§

impl<'a, T: Value> Handle<'a, T>

source

pub fn upcast<U: Value + SuperType<T>>(&self) -> Handle<'a, U>

Safely upcast a handle to a supertype.

This method does not require an execution context because it only copies a handle.

source

pub fn is_a<'b, U: Value, C: Context<'b>>(&self, cx: &mut C) -> bool

Tests whether this value is an instance of the given type.

§Example:
let v: Handle<JsValue> = cx.number(17).upcast();
v.is_a::<JsString, _>(&mut cx); // false
v.is_a::<JsNumber, _>(&mut cx); // true
v.is_a::<JsValue, _>(&mut cx);  // true
source

pub fn downcast<'b, U: Value, C: Context<'b>>( &self, cx: &mut C ) -> DowncastResult<'a, T, U>

Attempts to downcast a handle to another type, which may fail. A failure to downcast does not throw a JavaScript exception, so it’s OK to continue interacting with the JS engine if this method produces an Err result.

source

pub fn downcast_or_throw<'b, U: Value, C: Context<'b>>( &self, cx: &mut C ) -> JsResult<'a, U>

Attempts to downcast a handle to another type, raising a JavaScript TypeError exception on failure. This method is a convenient shorthand, equivalent to self.downcast::<U>().or_throw::<C>(cx).

source

pub fn strict_equals<'b, U: Value, C: Context<'b>>( &self, cx: &mut C, other: Handle<'b, U> ) -> bool

source§

impl<'cx> Handle<'cx, JsArrayBuffer>

source

pub fn region<T: Binary>(&self, offset: usize, len: usize) -> Region<'cx, T>

Returns a Region representing a typed region of this buffer, starting at offset and containing len elements of type T.

The region is not checked for validity by this method. Regions are only validated when they are converted to typed arrays.

§Example
let buf: Handle<JsArrayBuffer> = cx.argument(0)?;
let region = buf.region::<u32>(64, 8);
println!("offset={}, len={}, size={}", region.offset(), region.len(), region.size());

See the Region documentation for more information.

Trait Implementations§

source§

impl<'a, V: Value> Clone for Handle<'a, V>

source§

fn clone(&self) -> Self

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<'a, V: Debug + Value + 'a> Debug for Handle<'a, V>

source§

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

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

impl<'a, V: Value> Deref for Handle<'a, V>

§

type Target = V

The resulting type after dereferencing.
source§

fn deref(&self) -> &V

Dereferences the value.
source§

impl<'a, V: Value> DerefMut for Handle<'a, V>

source§

fn deref_mut(&mut self) -> &mut V

Mutably dereferences the value.
source§

impl<'a, K: Value> PropertyKey for Handle<'a, K>

source§

unsafe fn get_from<'c, C: Context<'c>>( self, cx: &mut C, out: &mut Value, obj: Value ) -> bool

source§

unsafe fn set_from<'c, C: Context<'c>>( self, cx: &mut C, out: &mut bool, obj: Value, val: Value ) -> bool

source§

impl<'a> ResultExt<Handle<'a, JsString>> for StringResult<'a>

source§

fn or_throw<'b, C: Context<'b>>(self, cx: &mut C) -> JsResult<'a, JsString>

source§

impl<'a, T: Value> ResultExt<Handle<'a, T>> for Result<Handle<'a, T>, DateError>

source§

fn or_throw<'b, C: Context<'b>>(self, cx: &mut C) -> JsResult<'a, T>

Creates an Error on error

source§

impl<'a, F: Value, T: Value> ResultExt<Handle<'a, T>> for DowncastResult<'a, F, T>

source§

fn or_throw<'b, C: Context<'b>>(self, cx: &mut C) -> JsResult<'a, T>

source§

impl<'a, 'b, T, E> ResultExt<Handle<'a, T>> for Result<Handle<'a, T>, Handle<'b, E>>
where T: Value, E: Value,

source§

fn or_throw<'cx, C: Context<'cx>>(self, cx: &mut C) -> JsResult<'a, T>

source§

impl<'cx, V> TryFromJs<'cx> for Handle<'cx, V>
where V: Value,

§

type Error = TypeExpected<V>

source§

fn try_from_js<C>( cx: &mut C, v: Handle<'cx, JsValue> ) -> NeonResult<Result<Self, Self::Error>>
where C: Context<'cx>,

source§

fn from_js<C>(cx: &mut C, v: Handle<'cx, JsValue>) -> NeonResult<Self>
where C: Context<'cx>,

source§

impl<'a, V: Value> Copy for Handle<'a, V>

Auto Trait Implementations§

§

impl<'a, V> Freeze for Handle<'a, V>
where <V as TransparentNoCopyWrapper>::Inner: Freeze,

§

impl<'a, V> RefUnwindSafe for Handle<'a, V>
where V: RefUnwindSafe, <V as TransparentNoCopyWrapper>::Inner: RefUnwindSafe,

§

impl<'a, V> Send for Handle<'a, V>
where V: Sync, <V as TransparentNoCopyWrapper>::Inner: Send,

§

impl<'a, V> Sync for Handle<'a, V>
where V: Sync, <V as TransparentNoCopyWrapper>::Inner: Sync,

§

impl<'a, V> Unpin for Handle<'a, V>
where <V as TransparentNoCopyWrapper>::Inner: Unpin,

§

impl<'a, V> UnwindSafe for Handle<'a, V>
where V: RefUnwindSafe, <V as TransparentNoCopyWrapper>::Inner: UnwindSafe,

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> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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<'cx, T> FromArgs<'cx> for T
where T: TryFromJs<'cx>,