Skip to main content

JsArg

Trait JsArg 

pub trait JsArg: Sized {
    // Required method
    fn from_js(value: JsValue) -> Result<Self, JsError>;

    // Provided method
    fn from_missing_js_arg() -> Result<Self, JsError> { ... }
}
Available on crate features js and std only.
Expand description

A typed host function argument, extracted from a JsValue.

Implemented for primitives, strings, common network types and containers; see the crate documentation for the full list. Implement it for your own types to use them directly as typed arguments in host functions registered via JsRuntimeBuilder::with_fn.

A failed extraction is thrown as a TypeError inside the calling script.

Required Methods§

fn from_js(value: JsValue) -> Result<Self, JsError>

Extract this argument from the given value.

Provided Methods§

fn from_missing_js_arg() -> Result<Self, JsError>

Extract this argument when the caller did not provide it.

Defaults to an arity error; optional arguments override this.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

§

impl JsArg for IpAddr

§

impl JsArg for SocketAddr

§

impl JsArg for bool

§

impl JsArg for f32

§

impl JsArg for f64

§

impl JsArg for i8

§

impl JsArg for i16

§

impl JsArg for i32

§

impl JsArg for i64

§

impl JsArg for i128

§

impl JsArg for isize

§

impl JsArg for u8

§

impl JsArg for u16

§

impl JsArg for u32

§

impl JsArg for u64

§

impl JsArg for u128

§

impl JsArg for usize

Implementors§

§

impl JsArg for Authority

§

impl JsArg for Domain

§

impl JsArg for Host

§

impl JsArg for IpNet

§

impl JsArg for Ipv4Addr

§

impl JsArg for Ipv6Addr

§

impl JsArg for JsArray

§

impl JsArg for JsObject

§

impl JsArg for JsStr

§

impl JsArg for JsValue

§

impl JsArg for SocketAddress

§

impl JsArg for String

§

impl<T> JsArg for Option<T>
where T: JsArg,

§

impl<T> JsArg for Serde<T>

§

impl<T> JsArg for Vec<T>
where T: JsArg,