mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-14 13:31:22 +00:00
Add a JsCast
trait specified in [RFC 2]
[RFC 2]: https://github.com/rustwasm/rfcs/pull/2
This commit is contained in:
19
src/lib.rs
19
src/lib.rs
@ -46,6 +46,9 @@ pub mod prelude {
|
||||
pub mod convert;
|
||||
pub mod describe;
|
||||
|
||||
mod cast;
|
||||
pub use cast::JsCast;
|
||||
|
||||
if_std! {
|
||||
extern crate std;
|
||||
use std::prelude::v1::*;
|
||||
@ -347,6 +350,22 @@ impl From<bool> for JsValue {
|
||||
}
|
||||
}
|
||||
|
||||
impl JsCast for JsValue {
|
||||
// everything is a `JsValue`!
|
||||
fn instanceof(_val: &JsValue) -> bool { true }
|
||||
fn unchecked_from_js(val: JsValue) -> Self { val }
|
||||
fn unchecked_from_js_ref(val: &JsValue) -> &Self { val }
|
||||
fn unchecked_from_js_mut(val: &mut JsValue) -> &mut Self { val }
|
||||
}
|
||||
|
||||
impl AsMut<JsValue> for JsValue {
|
||||
fn as_mut(&mut self) -> &mut JsValue { self }
|
||||
}
|
||||
|
||||
impl AsRef<JsValue> for JsValue {
|
||||
fn as_ref(&self) -> &JsValue { self }
|
||||
}
|
||||
|
||||
macro_rules! numbers {
|
||||
($($n:ident)*) => ($(
|
||||
impl PartialEq<$n> for JsValue {
|
||||
|
Reference in New Issue
Block a user