Skip to main content

JsValueExtension

Trait JsValueExtension 

Source
pub trait JsValueExtension {
    // Required methods
    fn try_as_u8(&self) -> Result<u8, Error>;
    fn try_as_u16(&self) -> Result<u16, Error>;
    fn try_as_u32(&self) -> Result<u32, Error>;
    fn try_as_u64(&self) -> Result<u64, Error>;
    fn try_as_vec_u8(&self) -> Result<Vec<u8>, Error>;
}
Expand description

Extension trait converting a JsValue into native Rust integer and byte types.

Required Methods§

Source

fn try_as_u8(&self) -> Result<u8, Error>

Convert the value to a u8, erroring if it is not a number or is out of range.

Source

fn try_as_u16(&self) -> Result<u16, Error>

Convert the value to a u16, erroring if it is not a number or is out of range.

Source

fn try_as_u32(&self) -> Result<u32, Error>

Convert the value to a u32, erroring if it is not a number or is out of range.

Source

fn try_as_u64(&self) -> Result<u64, Error>

Convert the value to a u64, accepting a hex string, a BigInt, or a number.

Source

fn try_as_vec_u8(&self) -> Result<Vec<u8>, Error>

Convert the value to a Vec<u8>, accepting a hex string or a byte array.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl JsValueExtension for JsValue

Implementors§