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 ArrayBuffer

Source§

impl<'cx> TryFromJs<'cx> for Buffer

Source§

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

Available on crate feature napi-5 only.
Source§

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

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 Boxed<T>
where T: Clone + 'static,

Source§

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