Merge pull request #1571 from alexcrichton/less-warnings

Use `dyn` with all trait objects
This commit is contained in:
Alex Crichton 2019-06-03 11:54:29 -05:00 committed by GitHub
commit 618b5d3531
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 148 additions and 146 deletions

View File

@ -166,7 +166,7 @@ impl ToTokens for ast::Struct {
impl wasm_bindgen::convert::IntoWasmAbi for #name {
type Abi = u32;
fn into_abi(self, _extra: &mut wasm_bindgen::convert::Stack)
fn into_abi(self, _extra: &mut dyn wasm_bindgen::convert::Stack)
-> u32
{
use wasm_bindgen::__rt::std::boxed::Box;
@ -179,7 +179,7 @@ impl ToTokens for ast::Struct {
impl wasm_bindgen::convert::FromWasmAbi for #name {
type Abi = u32;
unsafe fn from_abi(js: u32, _extra: &mut wasm_bindgen::convert::Stack)
unsafe fn from_abi(js: u32, _extra: &mut dyn wasm_bindgen::convert::Stack)
-> Self
{
use wasm_bindgen::__rt::std::boxed::Box;
@ -210,7 +210,7 @@ impl ToTokens for ast::Struct {
}
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
unsafe fn #new_fn(ptr: u32) -> u32 {
unsafe fn #new_fn(_: u32) -> u32 {
panic!("cannot convert to JsValue outside of the wasm target")
}
@ -242,7 +242,7 @@ impl ToTokens for ast::Struct {
unsafe fn ref_from_abi(
js: Self::Abi,
_extra: &mut wasm_bindgen::convert::Stack,
_extra: &mut dyn wasm_bindgen::convert::Stack,
) -> Self::Anchor {
let js = js as *mut wasm_bindgen::__rt::WasmRefCell<#name>;
wasm_bindgen::__rt::assert_not_null(js);
@ -257,7 +257,7 @@ impl ToTokens for ast::Struct {
unsafe fn ref_mut_from_abi(
js: Self::Abi,
_extra: &mut wasm_bindgen::convert::Stack,
_extra: &mut dyn wasm_bindgen::convert::Stack,
) -> Self::Anchor {
let js = js as *mut wasm_bindgen::__rt::WasmRefCell<#name>;
wasm_bindgen::__rt::assert_not_null(js);
@ -637,7 +637,7 @@ impl ToTokens for ast::ImportType {
type Abi = <JsValue as IntoWasmAbi>::Abi;
#[inline]
fn into_abi(self, extra: &mut Stack) -> Self::Abi {
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi {
self.obj.into_abi(extra)
}
}
@ -656,7 +656,7 @@ impl ToTokens for ast::ImportType {
type Abi = <JsValue as FromWasmAbi>::Abi;
#[inline]
unsafe fn from_abi(js: Self::Abi, extra: &mut Stack) -> Self {
unsafe fn from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self {
#rust_name {
obj: JsValue::from_abi(js, extra).into(),
}
@ -672,7 +672,7 @@ impl ToTokens for ast::ImportType {
type Abi = <&'a JsValue as IntoWasmAbi>::Abi;
#[inline]
fn into_abi(self, extra: &mut Stack) -> Self::Abi {
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi {
(&self.obj).into_abi(extra)
}
}
@ -682,7 +682,7 @@ impl ToTokens for ast::ImportType {
type Anchor = core::mem::ManuallyDrop<#rust_name>;
#[inline]
unsafe fn ref_from_abi(js: Self::Abi, extra: &mut Stack) -> Self::Anchor {
unsafe fn ref_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor {
let tmp = <JsValue as RefFromWasmAbi>::ref_from_abi(js, extra);
core::mem::ManuallyDrop::new(#rust_name {
obj: core::mem::ManuallyDrop::into_inner(tmp).into(),
@ -719,7 +719,7 @@ impl ToTokens for ast::ImportType {
fn #instanceof_shim(val: u32) -> u32;
}
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
unsafe fn #instanceof_shim(val: u32) -> u32 {
unsafe fn #instanceof_shim(_: u32) -> u32 {
panic!("cannot check instanceof on non-wasm targets");
}
unsafe {
@ -838,7 +838,7 @@ impl ToTokens for ast::ImportEnum {
wasm_bindgen::convert::IntoWasmAbi>::Abi;
#[inline]
fn into_abi(self, extra: &mut wasm_bindgen::convert::Stack) -> Self::Abi {
fn into_abi(self, extra: &mut dyn wasm_bindgen::convert::Stack) -> Self::Abi {
wasm_bindgen::JsValue::from(self).into_abi(extra)
}
}
@ -850,7 +850,7 @@ impl ToTokens for ast::ImportEnum {
unsafe fn from_abi(
js: Self::Abi,
extra: &mut wasm_bindgen::convert::Stack,
extra: &mut dyn wasm_bindgen::convert::Stack,
) -> Self {
#name::from_js_value(&wasm_bindgen::JsValue::from_abi(js, extra)).unwrap_or(#name::__Nonexhaustive)
}
@ -997,6 +997,7 @@ impl TryToTokens for ast::ImportFunction {
let attrs = &self.function.rust_attrs;
let arguments = &arguments;
let abi_arguments = &abi_arguments;
let abi_argument_names = &abi_argument_names;
let doc_comment = match &self.doc_comment {
None => "",
@ -1032,6 +1033,7 @@ impl TryToTokens for ast::ImportFunction {
}
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
unsafe fn #import_name(#(#abi_arguments),*) -> #abi_ret {
drop((#(#abi_argument_names),*));
panic!("cannot call wasm-bindgen imported functions on \
non-wasm targets");
}
@ -1125,7 +1127,7 @@ impl ToTokens for ast::Enum {
type Abi = u32;
#[inline]
fn into_abi(self, _extra: &mut wasm_bindgen::convert::Stack) -> u32 {
fn into_abi(self, _extra: &mut dyn wasm_bindgen::convert::Stack) -> u32 {
self as u32
}
}
@ -1137,7 +1139,7 @@ impl ToTokens for ast::Enum {
#[inline]
unsafe fn from_abi(
js: u32,
_extra: &mut wasm_bindgen::convert::Stack,
_extra: &mut dyn wasm_bindgen::convert::Stack,
) -> Self {
#(#cast_clauses else)* {
wasm_bindgen::throw_str("invalid enum value passed")
@ -1331,7 +1333,7 @@ impl ToTokens for ast::Dictionary {
impl IntoWasmAbi for #name {
type Abi = <Object as IntoWasmAbi>::Abi;
#[inline]
fn into_abi(self, extra: &mut Stack) -> Self::Abi {
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi {
self.obj.into_abi(extra)
}
}
@ -1339,7 +1341,7 @@ impl ToTokens for ast::Dictionary {
impl<'a> IntoWasmAbi for &'a #name {
type Abi = <&'a Object as IntoWasmAbi>::Abi;
#[inline]
fn into_abi(self, extra: &mut Stack) -> Self::Abi {
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi {
(&self.obj).into_abi(extra)
}
}
@ -1347,7 +1349,7 @@ impl ToTokens for ast::Dictionary {
impl FromWasmAbi for #name {
type Abi = <Object as FromWasmAbi>::Abi;
#[inline]
unsafe fn from_abi(abi: Self::Abi, extra: &mut Stack) -> Self {
unsafe fn from_abi(abi: Self::Abi, extra: &mut dyn Stack) -> Self {
#name { obj: Object::from_abi(abi, extra) }
}
}
@ -1370,7 +1372,7 @@ impl ToTokens for ast::Dictionary {
type Anchor = ManuallyDrop<#name>;
#[inline]
unsafe fn ref_from_abi(js: Self::Abi, extra: &mut Stack) -> Self::Anchor {
unsafe fn ref_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor {
let tmp = <Object as RefFromWasmAbi>::ref_from_abi(js, extra);
ManuallyDrop::new(#name {
obj: ManuallyDrop::into_inner(tmp),

View File

@ -52,7 +52,7 @@ impl Diagnostic {
}
}
pub fn spanned_error<T: Into<String>>(node: &ToTokens, text: T) -> Diagnostic {
pub fn spanned_error<T: Into<String>>(node: &dyn ToTokens, text: T) -> Diagnostic {
Diagnostic {
inner: Repr::Single {
text: text.into(),
@ -89,7 +89,7 @@ impl From<Error> for Diagnostic {
}
}
fn extract_spans(node: &ToTokens) -> Option<(Span, Span)> {
fn extract_spans(node: &dyn ToTokens) -> Option<(Span, Span)> {
let mut t = TokenStream::new();
node.to_tokens(&mut t);
let mut tokens = t.into_iter();

View File

@ -1086,7 +1086,7 @@ impl<'a> Context<'a> {
fn bind(
&mut self,
name: &str,
f: &Fn(&mut Self) -> Result<String, Error>,
f: &dyn Fn(&mut Self) -> Result<String, Error>,
) -> Result<(), Error> {
if !self.wasm_import_needed(name) {
return Ok(());

View File

@ -130,7 +130,7 @@ use wasm_bindgen::prelude::*;
pub struct JsFuture {
resolved: oneshot::Receiver<JsValue>,
rejected: oneshot::Receiver<JsValue>,
callbacks: Option<(Closure<FnMut(JsValue)>, Closure<FnMut(JsValue)>)>,
callbacks: Option<(Closure<dyn FnMut(JsValue)>, Closure<dyn FnMut(JsValue)>)>,
}
impl fmt::Debug for JsFuture {
@ -152,11 +152,11 @@ impl From<Promise> for JsFuture {
let mut tx1 = Some(tx1);
let resolve = Closure::wrap(Box::new(move |val| {
drop(tx1.take().unwrap().send(val));
}) as Box<FnMut(_)>);
}) as Box<dyn FnMut(_)>);
let mut tx2 = Some(tx2);
let reject = Closure::wrap(Box::new(move |val| {
drop(tx2.take().unwrap().send(val));
}) as Box<FnMut(_)>);
}) as Box<dyn FnMut(_)>);
js.then2(&resolve, &reject);
@ -233,7 +233,7 @@ where
//
// This isn't necessarily the greatest future executor in the world, but it
// should get the job done for now hopefully.
fn _future_to_promise(future: Box<Future<Item = JsValue, Error = JsValue>>) -> Promise {
fn _future_to_promise(future: Box<dyn Future<Item = JsValue, Error = JsValue>>) -> Promise {
let mut future = Some(executor::spawn(future));
return Promise::new(&mut |resolve, reject| {
Package::poll(&Arc::new(Package {
@ -247,7 +247,7 @@ fn _future_to_promise(future: Box<Future<Item = JsValue, Error = JsValue>>) -> P
struct Package {
// Our "spawned future". This'll have everything we need to poll the
// future and continue to move it forward.
spawn: RefCell<Spawn<Box<Future<Item = JsValue, Error = JsValue>>>>,
spawn: RefCell<Spawn<Box<dyn Future<Item = JsValue, Error = JsValue>>>>,
// The current state of this future, expressed in an enum below. This
// indicates whether we're currently polling the future, received a
@ -379,7 +379,7 @@ fn _future_to_promise(future: Box<Future<Item = JsValue, Error = JsValue>>) -> P
let myself = slot2.borrow_mut().take();
debug_assert!(myself.is_some());
Package::poll(&me);
}) as Box<FnMut(JsValue)>);
}) as Box<dyn FnMut(JsValue)>);
promise.then(&closure);
*slot.borrow_mut() = Some(closure);
}

View File

@ -158,7 +158,7 @@ extern "C" {
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
#[wasm_bindgen(method)]
pub fn every(this: &Array, predicate: &mut FnMut(JsValue, u32, Array) -> bool) -> bool;
pub fn every(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> bool;
/// The fill() method fills all the elements of an array from a start index
/// to an end index with a static value. The end index is not included.
@ -172,27 +172,27 @@ extern "C" {
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
#[wasm_bindgen(method)]
pub fn filter(this: &Array, predicate: &mut FnMut(JsValue, u32, Array) -> bool) -> Array;
pub fn filter(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> Array;
/// The `find()` method returns the value of the first element in the array that satisfies
/// the provided testing function. Otherwise `undefined` is returned.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
#[wasm_bindgen(method)]
pub fn find(this: &Array, predicate: &mut FnMut(JsValue, u32, Array) -> bool) -> JsValue;
pub fn find(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> JsValue;
/// The findIndex() method returns the index of the first element in the array that
/// satisfies the provided testing function. Otherwise -1 is returned.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
#[wasm_bindgen(method, js_name = findIndex)]
pub fn find_index(this: &Array, predicate: &mut FnMut(JsValue, u32, Array) -> bool) -> i32;
pub fn find_index(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> i32;
/// The `forEach()` method executes a provided function once for each array element.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
#[wasm_bindgen(method, js_name = forEach)]
pub fn for_each(this: &Array, callback: &mut FnMut(JsValue, u32, Array));
pub fn for_each(this: &Array, callback: &mut dyn FnMut(JsValue, u32, Array));
/// The includes() method determines whether an array includes a certain
/// element, returning true or false as appropriate.
@ -246,7 +246,7 @@ extern "C" {
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
#[wasm_bindgen(method)]
pub fn map(this: &Array, predicate: &mut FnMut(JsValue, u32, Array) -> JsValue) -> Array;
pub fn map(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> JsValue) -> Array;
/// The `Array.of()` method creates a new Array instance with a variable
/// number of arguments, regardless of number or type of the arguments.
@ -303,7 +303,7 @@ extern "C" {
#[wasm_bindgen(method)]
pub fn reduce(
this: &Array,
predicate: &mut FnMut(JsValue, JsValue, u32, Array) -> JsValue,
predicate: &mut dyn FnMut(JsValue, JsValue, u32, Array) -> JsValue,
initial_value: &JsValue,
) -> JsValue;
@ -314,7 +314,7 @@ extern "C" {
#[wasm_bindgen(method, js_name = reduceRight)]
pub fn reduce_right(
this: &Array,
predicate: &mut FnMut(JsValue, JsValue, u32, Array) -> JsValue,
predicate: &mut dyn FnMut(JsValue, JsValue, u32, Array) -> JsValue,
initial_value: &JsValue,
) -> JsValue;
@ -345,7 +345,7 @@ extern "C" {
/// Note: This method returns false for any condition put on an empty array.
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
#[wasm_bindgen(method)]
pub fn some(this: &Array, predicate: &mut FnMut(JsValue) -> bool) -> bool;
pub fn some(this: &Array, predicate: &mut dyn FnMut(JsValue) -> bool) -> bool;
/// The sort() method sorts the elements of an array in place and returns
/// the array. The sort is not necessarily stable. The default sort
@ -1147,7 +1147,7 @@ extern "C" {
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
#[wasm_bindgen(method, js_name = forEach)]
pub fn for_each(this: &Map, callback: &mut FnMut(JsValue, JsValue));
pub fn for_each(this: &Map, callback: &mut dyn FnMut(JsValue, JsValue));
/// The get() method returns a specified element from a Map object.
///
@ -2815,7 +2815,7 @@ extern "C" {
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
#[wasm_bindgen(method, js_name = forEach)]
pub fn for_each(this: &Set, callback: &mut FnMut(JsValue, JsValue, Set));
pub fn for_each(this: &Set, callback: &mut dyn FnMut(JsValue, JsValue, Set));
/// The `has()` method returns a boolean indicating whether an element with
/// the specified value exists in a [`Set`] object or not.
@ -4309,7 +4309,7 @@ extern "C" {
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
#[wasm_bindgen(constructor)]
pub fn new(cb: &mut FnMut(Function, Function)) -> Promise;
pub fn new(cb: &mut dyn FnMut(Function, Function)) -> Promise;
/// The `Promise.all(iterable)` method returns a single `Promise` that
/// resolves when all of the promises in the iterable argument have resolved
@ -4352,21 +4352,21 @@ extern "C" {
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
#[wasm_bindgen(method)]
pub fn catch(this: &Promise, cb: &Closure<FnMut(JsValue)>) -> Promise;
pub fn catch(this: &Promise, cb: &Closure<dyn FnMut(JsValue)>) -> Promise;
/// The `then()` method returns a `Promise`. It takes up to two arguments:
/// callback functions for the success and failure cases of the `Promise`.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
#[wasm_bindgen(method)]
pub fn then(this: &Promise, cb: &Closure<FnMut(JsValue)>) -> Promise;
pub fn then(this: &Promise, cb: &Closure<dyn FnMut(JsValue)>) -> Promise;
/// Same as `then`, only with both arguments provided.
#[wasm_bindgen(method, js_name = then)]
pub fn then2(
this: &Promise,
resolve: &Closure<FnMut(JsValue)>,
reject: &Closure<FnMut(JsValue)>,
resolve: &Closure<dyn FnMut(JsValue)>,
reject: &Closure<dyn FnMut(JsValue)>,
) -> Promise;
/// The `finally()` method returns a `Promise`. When the promise is settled,
@ -4380,7 +4380,7 @@ extern "C" {
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally)
#[wasm_bindgen(method)]
pub fn finally(this: &Promise, cb: &Closure<FnMut()>) -> Promise;
pub fn finally(this: &Promise, cb: &Closure<dyn FnMut()>) -> Promise;
}
/// Returns a handle to the global scope object.
@ -4499,7 +4499,7 @@ macro_rules! arrays {
/// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
/// types here.
#[wasm_bindgen(method, js_name = forEach)]
pub fn for_each(this: &$name, callback: &mut FnMut($ty, u32, $name));
pub fn for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name));
/// The `length` accessor property represents the length (in elements) of a
/// typed array.

View File

@ -148,7 +148,7 @@ struct State {
/// How to actually format output, either node.js or browser-specific
/// implementation.
formatter: Box<Formatter>,
formatter: Box<dyn Formatter>,
}
/// Representation of one test that needs to be executed.
@ -157,7 +157,7 @@ struct State {
/// future is polled.
struct Test {
name: String,
future: Box<Future<Item = (), Error = JsValue>>,
future: Box<dyn Future<Item = (), Error = JsValue>>,
output: Rc<RefCell<Output>>,
}
@ -211,7 +211,7 @@ impl Context {
console_error_panic_hook::set_once();
let formatter = match node::Node::new() {
Some(node) => Box::new(node) as Box<Formatter>,
Some(node) => Box::new(node) as Box<dyn Formatter>,
None => Box::new(browser::Browser::new()),
};
Context {
@ -558,7 +558,7 @@ struct TestFuture<F> {
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(catch)]
fn __wbg_test_invoke(f: &mut FnMut()) -> Result<(), JsValue>;
fn __wbg_test_invoke(f: &mut dyn FnMut()) -> Result<(), JsValue>;
}
impl<F: Future<Error = JsValue>> Future for TestFuture<F> {

View File

@ -196,16 +196,16 @@ fn callback() {
static mut HIT: bool = false;
let cb = Closure::wrap(Box::new(move || unsafe {
HIT = true;
}) as Box<FnMut()>);
}) as Box<dyn FnMut()>);
o.invoke(cb.as_ref().unchecked_ref());
assert!(unsafe { HIT });
}
let cb = Closure::wrap(Box::new(move |a, b| a + b) as Box<FnMut(u32, u32) -> u32>);
let cb = Closure::wrap(Box::new(move |a, b| a + b) as Box<dyn FnMut(u32, u32) -> u32>);
assert_eq!(o.call_add(cb.as_ref().unchecked_ref()), 3);
let cb = Closure::wrap(
Box::new(move |a: String, b| a.repeat(b)) as Box<FnMut(String, usize) -> String>
Box::new(move |a: String, b| a.repeat(b)) as Box<dyn FnMut(String, usize) -> String>
);
assert_eq!(o.call_repeat(cb.as_ref().unchecked_ref()), "abababab");
}

View File

@ -28,7 +28,7 @@ pub struct Error {
}
impl Fail for Error {
fn cause(&self) -> Option<&Fail> {
fn cause(&self) -> Option<&dyn Fail> {
self.inner.cause()
}

View File

@ -114,7 +114,7 @@ impl WorkerPool {
pub fn new(max: u32) -> Result<WorkerPool, JsValue> {
let callback = Closure::wrap(Box::new(|event: Event| {
console_log!("unhandled event: {}", event.type_());
}) as Box<FnMut(Event)>);
}) as Box<dyn FnMut(Event)>);
let mut workers = Vec::new();
for _ in 0..max {
// TODO: what do do about `./worker.js`:

View File

@ -7,7 +7,7 @@ fn window() -> web_sys::Window {
web_sys::window().expect("no global `window` exists")
}
fn request_animation_frame(f: &Closure<FnMut()>) {
fn request_animation_frame(f: &Closure<dyn FnMut()>) {
window()
.request_animation_frame(f.as_ref().unchecked_ref())
.expect("should register `requestAnimationFrame` OK");
@ -61,7 +61,7 @@ pub fn run() -> Result<(), JsValue> {
// Schedule ourself for another requestAnimationFrame callback.
request_animation_frame(f.borrow().as_ref().unwrap());
}) as Box<FnMut()>));
}) as Box<dyn FnMut()>));
request_animation_frame(g.borrow().as_ref().unwrap());
Ok(())

View File

@ -378,7 +378,7 @@ where
// NB: we use a specific `T` for this `Closure<T>` impl block to avoid every
// call site having to provide an explicit, turbo-fished type like
// `Closure::<FnOnce()>::once(...)`.
impl Closure<FnOnce()> {
impl Closure<dyn FnOnce()> {
/// Create a `Closure` from a function that can only be called once.
///
/// Since we have no way of enforcing that JS cannot attempt to call this
@ -475,19 +475,19 @@ where
{
type Abi = u32;
fn into_abi(self, extra: &mut Stack) -> u32 {
fn into_abi(self, extra: &mut dyn Stack) -> u32 {
(&*self.js).into_abi(extra)
}
}
fn _check() {
fn _assert<T: IntoWasmAbi>() {}
_assert::<&Closure<Fn()>>();
_assert::<&Closure<Fn(String)>>();
_assert::<&Closure<Fn() -> String>>();
_assert::<&Closure<FnMut()>>();
_assert::<&Closure<FnMut(String)>>();
_assert::<&Closure<FnMut() -> String>>();
_assert::<&Closure<dyn Fn()>>();
_assert::<&Closure<dyn Fn(String)>>();
_assert::<&Closure<dyn Fn() -> String>>();
_assert::<&Closure<dyn FnMut()>>();
_assert::<&Closure<dyn FnMut(String)>>();
_assert::<&Closure<dyn FnMut() -> String>>();
}
impl<T> fmt::Debug for Closure<T>
@ -541,7 +541,7 @@ macro_rules! doit {
($(
($($var:ident)*)
)*) => ($(
unsafe impl<$($var,)* R> WasmClosure for Fn($($var),*) -> R + 'static
unsafe impl<$($var,)* R> WasmClosure for dyn Fn($($var),*) -> R + 'static
where $($var: FromWasmAbi + 'static,)*
R: ReturnWasmAbi + 'static,
{
@ -559,7 +559,7 @@ macro_rules! doit {
// convert `ret` as it may throw (for `Result`, for
// example)
let ret = {
let f: *const Fn($($var),*) -> R =
let f: *const dyn Fn($($var),*) -> R =
FatPtr { fields: (a, b) }.ptr;
let mut _stack = GlobalStack::new();
$(
@ -584,7 +584,7 @@ macro_rules! doit {
if a == 0 {
return;
}
drop(Box::from_raw(FatPtr::<Fn($($var,)*) -> R> {
drop(Box::from_raw(FatPtr::<dyn Fn($($var,)*) -> R> {
fields: (a, b)
}.ptr));
}
@ -594,7 +594,7 @@ macro_rules! doit {
}
}
unsafe impl<$($var,)* R> WasmClosure for FnMut($($var),*) -> R + 'static
unsafe impl<$($var,)* R> WasmClosure for dyn FnMut($($var),*) -> R + 'static
where $($var: FromWasmAbi + 'static,)*
R: ReturnWasmAbi + 'static,
{
@ -612,9 +612,9 @@ macro_rules! doit {
// convert `ret` as it may throw (for `Result`, for
// example)
let ret = {
let f: *const FnMut($($var),*) -> R =
let f: *const dyn FnMut($($var),*) -> R =
FatPtr { fields: (a, b) }.ptr;
let f = f as *mut FnMut($($var),*) -> R;
let f = f as *mut dyn FnMut($($var),*) -> R;
let mut _stack = GlobalStack::new();
$(
let $var = <$var as FromWasmAbi>::from_abi($var, &mut _stack);
@ -634,7 +634,7 @@ macro_rules! doit {
if a == 0 {
return;
}
drop(Box::from_raw(FatPtr::<FnMut($($var,)*) -> R> {
drop(Box::from_raw(FatPtr::<dyn FnMut($($var,)*) -> R> {
fields: (a, b)
}.ptr));
}
@ -650,7 +650,7 @@ macro_rules! doit {
$($var: FromWasmAbi + 'static,)*
R: ReturnWasmAbi + 'static
{
type FnMut = FnMut($($var),*) -> R;
type FnMut = dyn FnMut($($var),*) -> R;
fn into_fn_mut(self) -> Box<Self::FnMut> {
let mut me = Some(self);
@ -682,7 +682,7 @@ macro_rules! doit {
drop(option_closure);
result
}) as Box<FnMut($($var),*) -> R>);
}) as Box<dyn FnMut($($var),*) -> R>);
let js_val = closure.as_ref().clone();
@ -714,7 +714,7 @@ doit! {
// just this one! Maybe someone else can figure out voodoo so we don't have to
// duplicate.
unsafe impl<A, R> WasmClosure for Fn(&A) -> R
unsafe impl<A, R> WasmClosure for dyn Fn(&A) -> R
where A: RefFromWasmAbi,
R: ReturnWasmAbi + 'static,
{
@ -732,7 +732,7 @@ unsafe impl<A, R> WasmClosure for Fn(&A) -> R
// convert `ret` as it may throw (for `Result`, for
// example)
let ret = {
let f: *const Fn(&A) -> R =
let f: *const dyn Fn(&A) -> R =
FatPtr { fields: (a, b) }.ptr;
let mut _stack = GlobalStack::new();
let arg = <A as RefFromWasmAbi>::ref_from_abi(arg, &mut _stack);
@ -751,7 +751,7 @@ unsafe impl<A, R> WasmClosure for Fn(&A) -> R
if a == 0 {
return;
}
drop(Box::from_raw(FatPtr::<Fn(&A) -> R> {
drop(Box::from_raw(FatPtr::<dyn Fn(&A) -> R> {
fields: (a, b)
}.ptr));
}
@ -761,7 +761,7 @@ unsafe impl<A, R> WasmClosure for Fn(&A) -> R
}
}
unsafe impl<A, R> WasmClosure for FnMut(&A) -> R
unsafe impl<A, R> WasmClosure for dyn FnMut(&A) -> R
where A: RefFromWasmAbi,
R: ReturnWasmAbi + 'static,
{
@ -779,9 +779,9 @@ unsafe impl<A, R> WasmClosure for FnMut(&A) -> R
// convert `ret` as it may throw (for `Result`, for
// example)
let ret = {
let f: *const FnMut(&A) -> R =
let f: *const dyn FnMut(&A) -> R =
FatPtr { fields: (a, b) }.ptr;
let f = f as *mut FnMut(&A) -> R;
let f = f as *mut dyn FnMut(&A) -> R;
let mut _stack = GlobalStack::new();
let arg = <A as RefFromWasmAbi>::ref_from_abi(arg, &mut _stack);
(*f)(&*arg)
@ -799,7 +799,7 @@ unsafe impl<A, R> WasmClosure for FnMut(&A) -> R
if a == 0 {
return;
}
drop(Box::from_raw(FatPtr::<FnMut(&A) -> R> {
drop(Box::from_raw(FatPtr::<dyn FnMut(&A) -> R> {
fields: (a, b)
}.ptr));
}
@ -815,7 +815,7 @@ impl<T, A, R> WasmClosureFnOnce<(&A,), R> for T
A: RefFromWasmAbi + 'static,
R: ReturnWasmAbi + 'static
{
type FnMut = FnMut(&A) -> R;
type FnMut = dyn FnMut(&A) -> R;
fn into_fn_mut(self) -> Box<Self::FnMut> {
let mut me = Some(self);
@ -847,7 +847,7 @@ impl<T, A, R> WasmClosureFnOnce<(&A,), R> for T
drop(option_closure);
result
}) as Box<FnMut(&A) -> R>);
}) as Box<dyn FnMut(&A) -> R>);
let js_val = closure.as_ref().clone();

View File

@ -8,13 +8,13 @@ use crate::throw_str;
macro_rules! stack_closures {
($( ($cnt:tt $invoke:ident $invoke_mut:ident $($var:ident)*) )*) => ($(
impl<'a, 'b, $($var,)* R> IntoWasmAbi for &'a (Fn($($var),*) -> R + 'b)
impl<'a, 'b, $($var,)* R> IntoWasmAbi for &'a (dyn Fn($($var),*) -> R + 'b)
where $($var: FromWasmAbi,)*
R: ReturnWasmAbi
{
type Abi = WasmSlice;
fn into_abi(self, _extra: &mut Stack) -> WasmSlice {
fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice {
unsafe {
let (a, b): (usize, usize) = mem::transmute(self);
WasmSlice { ptr: a as u32, len: b as u32 }
@ -34,7 +34,7 @@ macro_rules! stack_closures {
// Scope all local variables before we call `return_abi` to
// ensure they're all destroyed as `return_abi` may throw
let ret = {
let f: &Fn($($var),*) -> R = mem::transmute((a, b));
let f: &dyn Fn($($var),*) -> R = mem::transmute((a, b));
let mut _stack = GlobalStack::new();
$(
let $var = <$var as FromWasmAbi>::from_abi($var, &mut _stack);
@ -44,7 +44,7 @@ macro_rules! stack_closures {
ret.return_abi(&mut GlobalStack::new())
}
impl<'a, $($var,)* R> WasmDescribe for Fn($($var),*) -> R + 'a
impl<'a, $($var,)* R> WasmDescribe for dyn Fn($($var),*) -> R + 'a
where $($var: FromWasmAbi,)*
R: ReturnWasmAbi
{
@ -57,13 +57,13 @@ macro_rules! stack_closures {
}
}
impl<'a, 'b, $($var,)* R> IntoWasmAbi for &'a mut (FnMut($($var),*) -> R + 'b)
impl<'a, 'b, $($var,)* R> IntoWasmAbi for &'a mut (dyn FnMut($($var),*) -> R + 'b)
where $($var: FromWasmAbi,)*
R: ReturnWasmAbi
{
type Abi = WasmSlice;
fn into_abi(self, _extra: &mut Stack) -> WasmSlice {
fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice {
unsafe {
let (a, b): (usize, usize) = mem::transmute(self);
WasmSlice { ptr: a as u32, len: b as u32 }
@ -83,7 +83,7 @@ macro_rules! stack_closures {
// Scope all local variables before we call `return_abi` to
// ensure they're all destroyed as `return_abi` may throw
let ret = {
let f: &mut FnMut($($var),*) -> R = mem::transmute((a, b));
let f: &mut dyn FnMut($($var),*) -> R = mem::transmute((a, b));
let mut _stack = GlobalStack::new();
$(
let $var = <$var as FromWasmAbi>::from_abi($var, &mut _stack);
@ -93,7 +93,7 @@ macro_rules! stack_closures {
ret.return_abi(&mut GlobalStack::new())
}
impl<'a, $($var,)* R> WasmDescribe for FnMut($($var),*) -> R + 'a
impl<'a, $($var,)* R> WasmDescribe for dyn FnMut($($var),*) -> R + 'a
where $($var: FromWasmAbi,)*
R: ReturnWasmAbi
{
@ -120,14 +120,14 @@ stack_closures! {
(8 invoke8 invoke8_mut A B C D E F G H)
}
impl<'a, 'b, A, R> IntoWasmAbi for &'a (Fn(&A) -> R + 'b)
impl<'a, 'b, A, R> IntoWasmAbi for &'a (dyn Fn(&A) -> R + 'b)
where
A: RefFromWasmAbi,
R: ReturnWasmAbi,
{
type Abi = WasmSlice;
fn into_abi(self, _extra: &mut Stack) -> WasmSlice {
fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice {
unsafe {
let (a, b): (usize, usize) = mem::transmute(self);
WasmSlice {
@ -150,7 +150,7 @@ unsafe extern "C" fn invoke1_ref<A: RefFromWasmAbi, R: ReturnWasmAbi>(
// Scope all local variables before we call `return_abi` to
// ensure they're all destroyed as `return_abi` may throw
let ret = {
let f: &Fn(&A) -> R = mem::transmute((a, b));
let f: &dyn Fn(&A) -> R = mem::transmute((a, b));
let mut _stack = GlobalStack::new();
let arg = <A as RefFromWasmAbi>::ref_from_abi(arg, &mut _stack);
f(&*arg)
@ -158,7 +158,7 @@ unsafe extern "C" fn invoke1_ref<A: RefFromWasmAbi, R: ReturnWasmAbi>(
ret.return_abi(&mut GlobalStack::new())
}
impl<'a, A, R> WasmDescribe for Fn(&A) -> R + 'a
impl<'a, A, R> WasmDescribe for dyn Fn(&A) -> R + 'a
where
A: RefFromWasmAbi,
R: ReturnWasmAbi,
@ -172,14 +172,14 @@ where
}
}
impl<'a, 'b, A, R> IntoWasmAbi for &'a mut (FnMut(&A) -> R + 'b)
impl<'a, 'b, A, R> IntoWasmAbi for &'a mut (dyn FnMut(&A) -> R + 'b)
where
A: RefFromWasmAbi,
R: ReturnWasmAbi,
{
type Abi = WasmSlice;
fn into_abi(self, _extra: &mut Stack) -> WasmSlice {
fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice {
unsafe {
let (a, b): (usize, usize) = mem::transmute(self);
WasmSlice {
@ -202,7 +202,7 @@ unsafe extern "C" fn invoke1_mut_ref<A: RefFromWasmAbi, R: ReturnWasmAbi>(
// Scope all local variables before we call `return_abi` to
// ensure they're all destroyed as `return_abi` may throw
let ret = {
let f: &mut FnMut(&A) -> R = mem::transmute((a, b));
let f: &mut dyn FnMut(&A) -> R = mem::transmute((a, b));
let mut _stack = GlobalStack::new();
let arg = <A as RefFromWasmAbi>::ref_from_abi(arg, &mut _stack);
f(&*arg)
@ -210,7 +210,7 @@ unsafe extern "C" fn invoke1_mut_ref<A: RefFromWasmAbi, R: ReturnWasmAbi>(
ret.return_abi(&mut GlobalStack::new())
}
impl<'a, A, R> WasmDescribe for FnMut(&A) -> R + 'a
impl<'a, A, R> WasmDescribe for dyn FnMut(&A) -> R + 'a
where
A: RefFromWasmAbi,
R: ReturnWasmAbi,

View File

@ -64,21 +64,21 @@ macro_rules! type_wasm_native {
type Abi = $c;
#[inline]
fn into_abi(self, _extra: &mut Stack) -> $c { self as $c }
fn into_abi(self, _extra: &mut dyn Stack) -> $c { self as $c }
}
impl FromWasmAbi for $t {
type Abi = $c;
#[inline]
unsafe fn from_abi(js: $c, _extra: &mut Stack) -> Self { js as $t }
unsafe fn from_abi(js: $c, _extra: &mut dyn Stack) -> Self { js as $t }
}
impl IntoWasmAbi for Option<$t> {
type Abi = $r;
#[inline]
fn into_abi(self, _extra: &mut Stack) -> $r {
fn into_abi(self, _extra: &mut dyn Stack) -> $r {
match self {
None => $r {
present: 0,
@ -96,7 +96,7 @@ macro_rules! type_wasm_native {
type Abi = $r;
#[inline]
unsafe fn from_abi(js: $r, _extra: &mut Stack) -> Self {
unsafe fn from_abi(js: $r, _extra: &mut dyn Stack) -> Self {
if js.present == 0 {
None
} else {
@ -122,14 +122,14 @@ macro_rules! type_abi_as_u32 {
type Abi = u32;
#[inline]
fn into_abi(self, _extra: &mut Stack) -> u32 { self as u32 }
fn into_abi(self, _extra: &mut dyn Stack) -> u32 { self as u32 }
}
impl FromWasmAbi for $t {
type Abi = u32;
#[inline]
unsafe fn from_abi(js: u32, _extra: &mut Stack) -> Self { js as $t }
unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> Self { js as $t }
}
impl OptionIntoWasmAbi for $t {
@ -152,7 +152,7 @@ macro_rules! type_64 {
type Abi = Wasm64;
#[inline]
fn into_abi(self, _extra: &mut Stack) -> Wasm64 {
fn into_abi(self, _extra: &mut dyn Stack) -> Wasm64 {
Wasm64 {
low: self as u32,
high: (self >> 32) as u32,
@ -164,7 +164,7 @@ macro_rules! type_64 {
type Abi = Wasm64;
#[inline]
unsafe fn from_abi(js: Wasm64, _extra: &mut Stack) -> $t {
unsafe fn from_abi(js: Wasm64, _extra: &mut dyn Stack) -> $t {
$t::from(js.low) | ($t::from(js.high) << 32)
}
}
@ -173,7 +173,7 @@ macro_rules! type_64 {
type Abi = WasmOptional64;
#[inline]
fn into_abi(self, _extra: &mut Stack) -> WasmOptional64 {
fn into_abi(self, _extra: &mut dyn Stack) -> WasmOptional64 {
match self {
None => WasmOptional64 {
present: 0,
@ -195,7 +195,7 @@ macro_rules! type_64 {
type Abi = WasmOptional64;
#[inline]
unsafe fn from_abi(js: WasmOptional64, _extra: &mut Stack) -> Self {
unsafe fn from_abi(js: WasmOptional64, _extra: &mut dyn Stack) -> Self {
if js.present == 0 {
None
} else {
@ -212,7 +212,7 @@ impl IntoWasmAbi for bool {
type Abi = u32;
#[inline]
fn into_abi(self, _extra: &mut Stack) -> u32 {
fn into_abi(self, _extra: &mut dyn Stack) -> u32 {
self as u32
}
}
@ -221,7 +221,7 @@ impl FromWasmAbi for bool {
type Abi = u32;
#[inline]
unsafe fn from_abi(js: u32, _extra: &mut Stack) -> bool {
unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> bool {
js != 0
}
}
@ -244,7 +244,7 @@ impl IntoWasmAbi for char {
type Abi = u32;
#[inline]
fn into_abi(self, _extra: &mut Stack) -> u32 {
fn into_abi(self, _extra: &mut dyn Stack) -> u32 {
self as u32
}
}
@ -253,7 +253,7 @@ impl FromWasmAbi for char {
type Abi = u32;
#[inline]
unsafe fn from_abi(js: u32, _extra: &mut Stack) -> char {
unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> char {
char::from_u32_unchecked(js)
}
}
@ -275,7 +275,7 @@ impl OptionFromWasmAbi for char {
impl<T> IntoWasmAbi for *const T {
type Abi = u32;
fn into_abi(self, _extra: &mut Stack) -> u32 {
fn into_abi(self, _extra: &mut dyn Stack) -> u32 {
self as u32
}
}
@ -283,7 +283,7 @@ impl<T> IntoWasmAbi for *const T {
impl<T> FromWasmAbi for *const T {
type Abi = u32;
unsafe fn from_abi(js: u32, _extra: &mut Stack) -> *const T {
unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> *const T {
js as *const T
}
}
@ -291,7 +291,7 @@ impl<T> FromWasmAbi for *const T {
impl<T> IntoWasmAbi for *mut T {
type Abi = u32;
fn into_abi(self, _extra: &mut Stack) -> u32 {
fn into_abi(self, _extra: &mut dyn Stack) -> u32 {
self as u32
}
}
@ -299,7 +299,7 @@ impl<T> IntoWasmAbi for *mut T {
impl<T> FromWasmAbi for *mut T {
type Abi = u32;
unsafe fn from_abi(js: u32, _extra: &mut Stack) -> *mut T {
unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> *mut T {
js as *mut T
}
}
@ -308,7 +308,7 @@ impl IntoWasmAbi for JsValue {
type Abi = u32;
#[inline]
fn into_abi(self, _extra: &mut Stack) -> u32 {
fn into_abi(self, _extra: &mut dyn Stack) -> u32 {
let ret = self.idx;
mem::forget(self);
ret
@ -319,7 +319,7 @@ impl FromWasmAbi for JsValue {
type Abi = u32;
#[inline]
unsafe fn from_abi(js: u32, _extra: &mut Stack) -> JsValue {
unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> JsValue {
JsValue::_new(js)
}
}
@ -328,7 +328,7 @@ impl<'a> IntoWasmAbi for &'a JsValue {
type Abi = u32;
#[inline]
fn into_abi(self, _extra: &mut Stack) -> u32 {
fn into_abi(self, _extra: &mut dyn Stack) -> u32 {
self.idx
}
}
@ -338,7 +338,7 @@ impl RefFromWasmAbi for JsValue {
type Anchor = ManuallyDrop<JsValue>;
#[inline]
unsafe fn ref_from_abi(js: u32, _extra: &mut Stack) -> Self::Anchor {
unsafe fn ref_from_abi(js: u32, _extra: &mut dyn Stack) -> Self::Anchor {
ManuallyDrop::new(JsValue::_new(js))
}
}
@ -346,7 +346,7 @@ impl RefFromWasmAbi for JsValue {
impl<T: OptionIntoWasmAbi> IntoWasmAbi for Option<T> {
type Abi = T::Abi;
fn into_abi(self, extra: &mut Stack) -> T::Abi {
fn into_abi(self, extra: &mut dyn Stack) -> T::Abi {
match self {
None => T::none(),
Some(me) => me.into_abi(extra),
@ -357,7 +357,7 @@ impl<T: OptionIntoWasmAbi> IntoWasmAbi for Option<T> {
impl<T: OptionFromWasmAbi> FromWasmAbi for Option<T> {
type Abi = T::Abi;
unsafe fn from_abi(js: T::Abi, extra: &mut Stack) -> Self {
unsafe fn from_abi(js: T::Abi, extra: &mut dyn Stack) -> Self {
if T::is_none(&js) {
None
} else {
@ -369,7 +369,7 @@ impl<T: OptionFromWasmAbi> FromWasmAbi for Option<T> {
impl<T: IntoWasmAbi> IntoWasmAbi for Clamped<T> {
type Abi = T::Abi;
fn into_abi(self, extra: &mut Stack) -> Self::Abi {
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi {
self.0.into_abi(extra)
}
}
@ -377,7 +377,7 @@ impl<T: IntoWasmAbi> IntoWasmAbi for Clamped<T> {
impl<T: FromWasmAbi> FromWasmAbi for Clamped<T> {
type Abi = T::Abi;
unsafe fn from_abi(js: T::Abi, extra: &mut Stack) -> Self {
unsafe fn from_abi(js: T::Abi, extra: &mut dyn Stack) -> Self {
Clamped(T::from_abi(js, extra))
}
}
@ -386,7 +386,7 @@ impl IntoWasmAbi for () {
type Abi = ();
#[inline]
fn into_abi(self, _extra: &mut Stack) {
fn into_abi(self, _extra: &mut dyn Stack) {
self
}
}
@ -394,7 +394,7 @@ impl IntoWasmAbi for () {
impl<T: IntoWasmAbi> ReturnWasmAbi for Result<T, JsValue> {
type Abi = T::Abi;
fn return_abi(self, extra: &mut Stack) -> Self::Abi {
fn return_abi(self, extra: &mut dyn Stack) -> Self::Abi {
match self {
Ok(v) => v.into_abi(extra),
Err(e) => crate::throw_val(e),

View File

@ -32,7 +32,7 @@ macro_rules! vectors {
type Abi = WasmSlice;
#[inline]
fn into_abi(self, extra: &mut Stack) -> WasmSlice {
fn into_abi(self, extra: &mut dyn Stack) -> WasmSlice {
let ptr = self.as_ptr();
let len = self.len();
mem::forget(self);
@ -51,7 +51,7 @@ macro_rules! vectors {
type Abi = WasmSlice;
#[inline]
unsafe fn from_abi(js: WasmSlice, extra: &mut Stack) -> Self {
unsafe fn from_abi(js: WasmSlice, extra: &mut dyn Stack) -> Self {
let ptr = <*mut $t>::from_abi(js.ptr, extra);
let len = js.len as usize;
Vec::from_raw_parts(ptr, len, len).into_boxed_slice()
@ -67,7 +67,7 @@ macro_rules! vectors {
type Abi = WasmSlice;
#[inline]
fn into_abi(self, extra: &mut Stack) -> WasmSlice {
fn into_abi(self, extra: &mut dyn Stack) -> WasmSlice {
WasmSlice {
ptr: self.as_ptr().into_abi(extra),
len: self.len() as u32,
@ -83,7 +83,7 @@ macro_rules! vectors {
type Abi = WasmSlice;
#[inline]
fn into_abi(self, extra: &mut Stack) -> WasmSlice {
fn into_abi(self, extra: &mut dyn Stack) -> WasmSlice {
(&*self).into_abi(extra)
}
}
@ -97,7 +97,7 @@ macro_rules! vectors {
type Anchor = &'static [$t];
#[inline]
unsafe fn ref_from_abi(js: WasmSlice, extra: &mut Stack) -> &'static [$t] {
unsafe fn ref_from_abi(js: WasmSlice, extra: &mut dyn Stack) -> &'static [$t] {
slice::from_raw_parts(
<*const $t>::from_abi(js.ptr, extra),
js.len as usize,
@ -110,7 +110,7 @@ macro_rules! vectors {
type Anchor = &'static mut [$t];
#[inline]
unsafe fn ref_mut_from_abi(js: WasmSlice, extra: &mut Stack)
unsafe fn ref_mut_from_abi(js: WasmSlice, extra: &mut dyn Stack)
-> &'static mut [$t]
{
slice::from_raw_parts_mut(
@ -130,7 +130,7 @@ if_std! {
impl<T> IntoWasmAbi for Vec<T> where Box<[T]>: IntoWasmAbi<Abi = WasmSlice> {
type Abi = <Box<[T]> as IntoWasmAbi>::Abi;
fn into_abi(self, extra: &mut Stack) -> Self::Abi {
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi {
self.into_boxed_slice().into_abi(extra)
}
}
@ -142,7 +142,7 @@ if_std! {
impl<T> FromWasmAbi for Vec<T> where Box<[T]>: FromWasmAbi<Abi = WasmSlice> {
type Abi = <Box<[T]> as FromWasmAbi>::Abi;
unsafe fn from_abi(js: Self::Abi, extra: &mut Stack) -> Self {
unsafe fn from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self {
<Box<[T]>>::from_abi(js, extra).into()
}
}
@ -155,7 +155,7 @@ if_std! {
type Abi = <Vec<u8> as IntoWasmAbi>::Abi;
#[inline]
fn into_abi(self, extra: &mut Stack) -> Self::Abi {
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi {
self.into_bytes().into_abi(extra)
}
}
@ -168,7 +168,7 @@ if_std! {
type Abi = <Vec<u8> as FromWasmAbi>::Abi;
#[inline]
unsafe fn from_abi(js: Self::Abi, extra: &mut Stack) -> Self {
unsafe fn from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self {
String::from_utf8_unchecked(<Vec<u8>>::from_abi(js, extra))
}
}
@ -182,7 +182,7 @@ impl<'a> IntoWasmAbi for &'a str {
type Abi = <&'a [u8] as IntoWasmAbi>::Abi;
#[inline]
fn into_abi(self, extra: &mut Stack) -> Self::Abi {
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi {
self.as_bytes().into_abi(extra)
}
}
@ -198,7 +198,7 @@ impl RefFromWasmAbi for str {
type Anchor = &'static str;
#[inline]
unsafe fn ref_from_abi(js: Self::Abi, extra: &mut Stack) -> Self::Anchor {
unsafe fn ref_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor {
str::from_utf8_unchecked(<[u8]>::ref_from_abi(js, extra))
}
}
@ -210,7 +210,7 @@ if_std! {
type Abi = WasmSlice;
#[inline]
fn into_abi(self, extra: &mut Stack) -> WasmSlice {
fn into_abi(self, extra: &mut dyn Stack) -> WasmSlice {
let ptr = self.as_ptr();
let len = self.len();
mem::forget(self);
@ -229,7 +229,7 @@ if_std! {
type Abi = WasmSlice;
#[inline]
unsafe fn from_abi(js: WasmSlice, extra: &mut Stack) -> Self {
unsafe fn from_abi(js: WasmSlice, extra: &mut dyn Stack) -> Self {
let ptr = <*mut JsValue>::from_abi(js.ptr, extra);
let len = js.len as usize;
Vec::from_raw_parts(ptr, len, len).into_boxed_slice()

View File

@ -13,7 +13,7 @@ pub trait IntoWasmAbi: WasmDescribe {
/// Convert `self` into `Self::Abi` so that it can be sent across the wasm
/// ABI boundary.
fn into_abi(self, extra: &mut Stack) -> Self::Abi;
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi;
}
/// A trait for anything that can be recovered by-value from the wasm ABI
@ -32,7 +32,7 @@ pub trait FromWasmAbi: WasmDescribe {
/// This is only safe to call when -- and implementations may assume that --
/// the supplied `Self::Abi` was previously generated by a call to `<Self as
/// IntoWasmAbi>::into_abi()` or the moral equivalent in JS.
unsafe fn from_abi(js: Self::Abi, extra: &mut Stack) -> Self;
unsafe fn from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self;
}
/// A trait for anything that can be recovered as some sort of shared reference
@ -55,7 +55,7 @@ pub trait RefFromWasmAbi: WasmDescribe {
/// # Safety
///
/// Same as `FromWasmAbi::from_abi`.
unsafe fn ref_from_abi(js: Self::Abi, extra: &mut Stack) -> Self::Anchor;
unsafe fn ref_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor;
}
/// Dual of the `RefFromWasmAbi` trait, except for mutable references.
@ -65,7 +65,7 @@ pub trait RefMutFromWasmAbi: WasmDescribe {
/// Same as `RefFromWasmAbi::Anchor`
type Anchor: DerefMut<Target = Self>;
/// Same as `RefFromWasmAbi::ref_from_abi`
unsafe fn ref_mut_from_abi(js: Self::Abi, extra: &mut Stack) -> Self::Anchor;
unsafe fn ref_mut_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor;
}
/// Indicates that this type can be passed to JS as `Option<Self>`.
@ -120,12 +120,12 @@ pub trait ReturnWasmAbi: WasmDescribe {
/// Same as `IntoWasmAbi::into_abi`, except that it may throw and never
/// return in the case of `Err`.
fn return_abi(self, extra: &mut Stack) -> Self::Abi;
fn return_abi(self, extra: &mut dyn Stack) -> Self::Abi;
}
impl<T: IntoWasmAbi> ReturnWasmAbi for T {
type Abi = T::Abi;
fn return_abi(self, extra: &mut Stack) -> Self::Abi {
fn return_abi(self, extra: &mut dyn Stack) -> Self::Abi {
self.into_abi(extra)
}
}