neon::types::extract

Trait TryFromJs

Source
pub trait TryFromJs<'cx>
where Self: Sealed + Sized,
{ type Error: TryIntoJs<'cx>; // Required method fn try_from_js( cx: &mut Cx<'cx>, v: Handle<'cx, JsValue>, ) -> NeonResult<Result<Self, Self::Error>>; // Provided method fn from_js(cx: &mut Cx<'cx>, v: Handle<'cx, JsValue>) -> NeonResult<Self> { ... } }
Expand description

Extract Rust data from a JavaScript value

Required Associated Types§

Required Methods§

Source

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

Extract this Rust type from a JavaScript value

Provided Methods§

Source

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

Same as TryFromJs, but all errors are converted to JavaScript exceptions

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'cx> TryFromJs<'cx> for bool

Source§

type Error = TypeExpected<JsBoolean>

Source§

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

Source§

impl<'cx> TryFromJs<'cx> for f64

Source§

type Error = TypeExpected<JsNumber>

Source§

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

Source§

impl<'cx> TryFromJs<'cx> for ()

Source§

type Error = Infallible

Source§

fn try_from_js( _cx: &mut Cx<'cx>, _v: Handle<'cx, JsValue>, ) -> NeonResult<Result<Self, Self::Error>>

Source§

impl<'cx> TryFromJs<'cx> for String

Source§

type Error = TypeExpected<JsString>

Source§

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

Source§

impl<'cx, L, R> TryFromJs<'cx> for Either<L, R>
where L: TryFromJs<'cx>, R: TryFromJs<'cx>,

Source§

type Error = Error<<L as TryFromJs<'cx>>::Error, <R as TryFromJs<'cx>>::Error>

Source§

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

Source§

impl<'cx, T> TryFromJs<'cx> for Option<T>
where T: TryFromJs<'cx>,

Source§

type Error = <T as TryFromJs<'cx>>::Error

Source§

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

Source§

impl<'cx, T> TryFromJs<'cx> for Vec<T>
where JsTypedArray<T>: Value, T: Binary,

Source§

type Error = TypeExpected<JsTypedArray<T>>

Source§

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

Implementors§

Source§

impl<'cx> TryFromJs<'cx> for Date

Available on crate feature napi-5 only.
Source§

impl<'cx, B> TryFromJs<'cx> for ArrayBuffer<B>
where for<'b> B: From<&'b [u8]>,

Source§

impl<'cx, B> TryFromJs<'cx> for Buffer<B>
where for<'b> B: From<&'b [u8]>,

Source§

impl<'cx, O> TryFromJs<'cx> for Root<O>
where O: Object,

Source§

impl<'cx, T> TryFromJs<'cx> for BigInt64Array<T>
where for<'a> T: From<&'a [i64]>,

Source§

impl<'cx, T> TryFromJs<'cx> for BigUint64Array<T>
where for<'a> T: From<&'a [u64]>,

Source§

impl<'cx, T> TryFromJs<'cx> for Boxed<T>
where T: Clone + 'static,

Source§

impl<'cx, T> TryFromJs<'cx> for Float32Array<T>
where for<'a> T: From<&'a [f32]>,

Source§

impl<'cx, T> TryFromJs<'cx> for Float64Array<T>
where for<'a> T: From<&'a [f64]>,

Source§

impl<'cx, T> TryFromJs<'cx> for Int8Array<T>
where for<'a> T: From<&'a [i8]>,

Source§

impl<'cx, T> TryFromJs<'cx> for Int16Array<T>
where for<'a> T: From<&'a [i16]>,

Source§

impl<'cx, T> TryFromJs<'cx> for Int32Array<T>
where for<'a> T: From<&'a [i32]>,

Source§

impl<'cx, T> TryFromJs<'cx> for Json<T>
where for<'de> T: Deserialize<'de>,

Available on crate feature serde only.
Source§

impl<'cx, T> TryFromJs<'cx> for Uint8Array<T>
where for<'a> T: From<&'a [u8]>,

Source§

impl<'cx, T> TryFromJs<'cx> for Uint16Array<T>
where for<'a> T: From<&'a [u16]>,

Source§

impl<'cx, T> TryFromJs<'cx> for Uint32Array<T>
where for<'a> T: From<&'a [u32]>,

Source§

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