Struct wasm_bindgen::JsValue
[−]
[src]
pub struct JsValue { /* fields omitted */ }
Representation of an object owned by JS.
A JsValue
doesn't actually live in Rust right now but actually in a table
owned by the wasm-bindgen
generated JS glue code. Eventually the ownership
will transfer into wasm directly and this will likely become more efficient,
but for now it may be slightly slow.
Methods
impl JsValue
[src]
pub fn from_str(s: &str) -> JsValue
[src]
Creates a new JS value which is a string.
The utf-8 string provided is copied to the JS heap and the string will be owned by the JS garbage collector.
pub fn from_f64(n: f64) -> JsValue
[src]
Creates a new JS value which is a number.
This function creates a JS value representing a number (a heap allocated number) and returns a handle to the JS version of it.
pub fn from_bool(b: bool) -> JsValue
[src]
Creates a new JS value which is a boolean.
This function creates a JS object representing a boolean (a heap allocated boolean) and returns a handle to the JS version of it.
pub fn undefined() -> JsValue
[src]
Creates a new JS value representing undefined
.
pub fn null() -> JsValue
[src]
Creates a new JS value representing null
.
pub fn symbol(description: Option<&str>) -> JsValue
[src]
Creates a new JS symbol with the optional description specified.
This function will invoke the Symbol
constructor in JS and return the
JS object corresponding to the symbol created.
pub fn as_f64(&self) -> Option<f64>
[src]
Returns the f64
value of this JS value if it's an instance of a
number.
If this JS value is not an instance of a number then this returns
None
.
pub fn as_string(&self) -> Option<String>
[src]
Returns the String
of this JS value if it's an instance of a
string and it's valid utf-8.
If this JS value is not an instance of a string or if it's not valid
utf-8 then this returns None
.
pub fn as_bool(&self) -> Option<bool>
[src]
Returns the bool
value of this JS value if it's an instance of a
boolean.
If this JS value is not an instance of a boolean then this returns
None
.
pub fn is_null(&self) -> bool
[src]
Tests whether this JS value is null
pub fn is_undefined(&self) -> bool
[src]
Tests whether this JS value is undefined
pub fn is_symbol(&self) -> bool
[src]
Tests whether the type of this JS value is symbol
Trait Implementations
impl WasmBoundary for JsValue
[src]
type Js = u32
const DESCRIPTOR: u32
DESCRIPTOR: u32 = DESCRIPTOR_JS_OWNED
fn into_js(self) -> u32
[src]
unsafe fn from_js(js: u32) -> JsValue
[src]
impl ToRefWasmBoundary for JsValue
[src]
impl FromRefWasmBoundary for JsValue
[src]
type RefAnchor = ManuallyDrop<JsValue>
unsafe fn from_js_ref(js: u32) -> ManuallyDrop<JsValue>
[src]
impl<'a> From<&'a str> for JsValue
[src]
impl<'a> From<&'a String> for JsValue
[src]
impl From<bool> for JsValue
[src]
impl From<i8> for JsValue
[src]
impl From<u8> for JsValue
[src]
impl From<i16> for JsValue
[src]
impl From<u16> for JsValue
[src]
impl From<i32> for JsValue
[src]
impl From<u32> for JsValue
[src]
impl From<f32> for JsValue
[src]
impl From<f64> for JsValue
[src]
impl Clone for JsValue
[src]
fn clone(&self) -> JsValue
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more