mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-23 09:41:33 +00:00
Overhaul the conversion traits
This commit overhauls the conversion traits used for types crossing the Rust/JS boundary. Previously there were a few ad-hoc traits but now there've been slightly reduced and decoupled. Conversion from Rust values to JS values is now exclusively done through `IntoWasmAbi` with no special treatment for references. Conversion from JS to Rust is a bit trickier as we want to create references in Rust which have implications in terms of safety. As a result there are now three traits for this, `FromWasmAbi`, `RefFromWasmAbi`, and `RefMutFromWasmAbi`. These three traits are implemented for various types and specially dispatched to depending on the type of argument in the code generator. The goal of this commit is to lay the groundwork for using these traits in closures with straightforward-ish definitions.
This commit is contained in:
@ -13,7 +13,7 @@ use std::cell::UnsafeCell;
|
||||
use std::ops::Deref;
|
||||
use std::ptr;
|
||||
|
||||
use convert::WasmBoundary;
|
||||
use convert::FromWasmAbi;
|
||||
|
||||
/// A module which is typically glob imported from:
|
||||
///
|
||||
@ -295,7 +295,7 @@ pub struct JsStatic<T> {
|
||||
unsafe impl<T: Sync> Sync for JsStatic<T> {}
|
||||
unsafe impl<T: Send> Send for JsStatic<T> {}
|
||||
|
||||
impl<T: WasmBoundary> Deref for JsStatic<T> {
|
||||
impl<T: FromWasmAbi + 'static> Deref for JsStatic<T> {
|
||||
type Target = T;
|
||||
fn deref(&self) -> &T {
|
||||
unsafe {
|
||||
|
Reference in New Issue
Block a user