traits of a wasm_bindgen type #3688
Unanswered
nearest-river
asked this question in
Q&A
Replies: 1 comment
-
You can find out by using #![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
use wasm_bindgen::prelude::*;
struct Foo {
foo: Vec<u8>,
}
#[automatically_derived]
impl wasm_bindgen::describe::WasmDescribe for Foo {
fn describe() {
use wasm_bindgen::__wbindgen_if_not_std;
use wasm_bindgen::describe::*;
inform(RUST_STRUCT);
inform(3u32);
inform(70u32);
inform(111u32);
inform(111u32);
}
}
#[automatically_derived]
impl wasm_bindgen::convert::IntoWasmAbi for Foo {
type Abi = u32;
fn into_abi(self) -> u32 {
use wasm_bindgen::__rt::std::boxed::Box;
use wasm_bindgen::__rt::WasmRefCell;
Box::into_raw(Box::new(WasmRefCell::new(self))) as u32
}
}
#[automatically_derived]
impl wasm_bindgen::convert::FromWasmAbi for Foo {
type Abi = u32;
unsafe fn from_abi(js: u32) -> Self {
use wasm_bindgen::__rt::std::boxed::Box;
use wasm_bindgen::__rt::{assert_not_null, WasmRefCell};
let ptr = js as *mut WasmRefCell<Foo>;
assert_not_null(ptr);
let js = Box::from_raw(ptr);
(*js).borrow_mut();
js.into_inner()
}
}
#[automatically_derived]
impl wasm_bindgen::__rt::core::convert::From<Foo> for wasm_bindgen::JsValue {
fn from(value: Foo) -> Self {
let ptr = wasm_bindgen::convert::IntoWasmAbi::into_abi(value);
#[link(wasm_import_module = "__wbindgen_placeholder__")]
#[cfg(
all(
target_arch = "wasm32",
not(any(target_os = "emscripten", target_os = "wasi"))
)
)]
extern "C" {
fn __wbg_foo_new(ptr: u32) -> u32;
}
unsafe {
<wasm_bindgen::JsValue as wasm_bindgen::convert::FromWasmAbi>::from_abi(
__wbg_foo_new(ptr),
)
}
}
}
#[cfg(
all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))
)]
#[automatically_derived]
const _: () = {
#[no_mangle]
#[doc(hidden)]
pub unsafe extern "C" fn __wbg_foo_free(ptr: u32) {
let _ = <Foo as wasm_bindgen::convert::FromWasmAbi>::from_abi(ptr);
}
};
#[automatically_derived]
impl wasm_bindgen::convert::RefFromWasmAbi for Foo {
type Abi = u32;
type Anchor = wasm_bindgen::__rt::Ref<'static, Foo>;
unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor {
let js = js as *mut wasm_bindgen::__rt::WasmRefCell<Foo>;
wasm_bindgen::__rt::assert_not_null(js);
(*js).borrow()
}
}
#[automatically_derived]
impl wasm_bindgen::convert::RefMutFromWasmAbi for Foo {
type Abi = u32;
type Anchor = wasm_bindgen::__rt::RefMut<'static, Foo>;
unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor {
let js = js as *mut wasm_bindgen::__rt::WasmRefCell<Foo>;
wasm_bindgen::__rt::assert_not_null(js);
(*js).borrow_mut()
}
}
#[automatically_derived]
impl wasm_bindgen::convert::LongRefFromWasmAbi for Foo {
type Abi = u32;
type Anchor = wasm_bindgen::__rt::Ref<'static, Foo>;
unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor {
<Self as wasm_bindgen::convert::RefFromWasmAbi>::ref_from_abi(js)
}
}
#[automatically_derived]
impl wasm_bindgen::convert::OptionIntoWasmAbi for Foo {
#[inline]
fn none() -> Self::Abi {
0
}
}
#[automatically_derived]
impl wasm_bindgen::convert::OptionFromWasmAbi for Foo {
#[inline]
fn is_none(abi: &Self::Abi) -> bool {
*abi == 0
}
}
#[allow(clippy::all)]
impl wasm_bindgen::__rt::core::convert::TryFrom<wasm_bindgen::JsValue> for Foo {
type Error = wasm_bindgen::JsValue;
fn try_from(
value: wasm_bindgen::JsValue,
) -> wasm_bindgen::__rt::std::result::Result<Self, Self::Error> {
let idx = wasm_bindgen::convert::IntoWasmAbi::into_abi(&value);
#[link(wasm_import_module = "__wbindgen_placeholder__")]
#[cfg(
all(
target_arch = "wasm32",
not(any(target_os = "emscripten", target_os = "wasi"))
)
)]
extern "C" {
fn __wbg_foo_unwrap(ptr: u32) -> u32;
}
let ptr = unsafe { __wbg_foo_unwrap(idx) };
if ptr == 0 {
wasm_bindgen::__rt::std::result::Result::Err(value)
} else {
wasm_bindgen::__rt::std::mem::forget(value);
unsafe {
wasm_bindgen::__rt::std::result::Result::Ok(
<Self as wasm_bindgen::convert::FromWasmAbi>::from_abi(ptr),
)
}
}
}
}
impl wasm_bindgen::describe::WasmDescribeVector for Foo {
fn describe_vector() {
use wasm_bindgen::describe::*;
inform(VECTOR);
inform(NAMED_EXTERNREF);
inform(3u32);
inform(70u32);
inform(111u32);
inform(111u32);
}
}
impl wasm_bindgen::convert::VectorIntoWasmAbi for Foo {
type Abi = <wasm_bindgen::__rt::std::boxed::Box<
[wasm_bindgen::JsValue],
> as wasm_bindgen::convert::IntoWasmAbi>::Abi;
fn vector_into_abi(vector: wasm_bindgen::__rt::std::boxed::Box<[Foo]>) -> Self::Abi {
wasm_bindgen::convert::js_value_vector_into_abi(vector)
}
}
impl wasm_bindgen::convert::VectorFromWasmAbi for Foo {
type Abi = <wasm_bindgen::__rt::std::boxed::Box<
[wasm_bindgen::JsValue],
> as wasm_bindgen::convert::FromWasmAbi>::Abi;
unsafe fn vector_from_abi(
js: Self::Abi,
) -> wasm_bindgen::__rt::std::boxed::Box<[Foo]> {
wasm_bindgen::convert::js_value_vector_from_abi(js)
}
}
#[cfg(target_arch = "wasm32")]
#[automatically_derived]
const _: () = {
static _INCLUDED_FILES: &[&str] = &[];
#[link_section = "__wasm_bindgen_unstable"]
pub static _GENERATED: [u8; 112usize] = *b".\x00\x00\x00{\"schema_version\":\"0.2.88\",\"version\":\"0.2.88\"}:\x00\x00\x00\x00\x00\x00\x01\x03Foo\x00\x00\x00\x01\x00\x00\x00(wasm-bindgen-playground-db5fbe5f033bb9af\x00\x00";
}; Most of them are internal to Another solution would be running |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
what are the traits that the wasm_bindgen impls for a type.
Example
the intellisence says that it has 12 implementations but doesn't show the traits
Beta Was this translation helpful? Give feedback.
All reactions