@@ -13,26 +13,59 @@ use describe::*;
13
13
#[ cfg( feature = "std" ) ]
14
14
use std:: prelude:: v1:: * ;
15
15
16
- #[ derive( PartialEq , Eq , Copy , Clone ) ]
17
- pub struct Descriptor {
18
- #[ doc( hidden) ]
19
- pub __x : [ u8 ; 4 ] ,
20
- }
21
-
16
+ /// A trait for anything that can be converted into a type that can cross the
17
+ /// wasm ABI directly, eg `u32` or `f64`.
18
+ ///
19
+ /// This is the opposite operation as `FromWasmAbi` and `Ref[Mut]FromWasmAbi`.
22
20
pub trait IntoWasmAbi : WasmDescribe {
21
+ /// The wasm ABI type that this converts into when crossing the ABI
22
+ /// boundary.
23
23
type Abi : WasmAbi ;
24
+
25
+ /// Convert `self` into `Self::Abi` so that it can be sent across the wasm
26
+ /// ABI boundary.
24
27
fn into_abi ( self , extra : & mut Stack ) -> Self :: Abi ;
25
28
}
26
29
30
+ /// A trait for anything that can be recovered by-value from the wasm ABI
31
+ /// boundary, eg a Rust `u8` can be recovered from the wasm ABI `u32` type.
32
+ ///
33
+ /// This is the by-value variant of the opposite operation as `IntoWasmAbi`.
27
34
pub trait FromWasmAbi : WasmDescribe {
35
+ /// The wasm ABI type that this converts from when coming back out from the
36
+ /// ABI boundary.
28
37
type Abi : WasmAbi ;
29
- unsafe fn from_abi ( js : Self :: Abi , extra : & mut Stack ) -> Self ;
30
38
39
+ /// Recover a `Self` from `Self::Abi`.
40
+ ///
41
+ /// # Safety
42
+ ///
43
+ /// This is only safe to call when -- and implementations may assume that --
44
+ /// the supplied `Self::Abi` was previously generated by a call to `<Self as
45
+ /// IntoWasmAbi>::into_abi()` or the moral equivalent in JS.
46
+ unsafe fn from_abi ( js : Self :: Abi , extra : & mut Stack ) -> Self ;
31
47
}
32
48
49
+ /// A trait for anything that can be recovered as some sort of shared reference
50
+ /// from the wasm ABI boundary.
51
+ ///
52
+ /// This is the shared reference variant of the opposite operation as
53
+ /// `IntoWasmAbi`.
33
54
pub trait RefFromWasmAbi : WasmDescribe {
55
+ /// The wasm ABI type references to `Self` are recovered from.
34
56
type Abi : WasmAbi ;
57
+
58
+ /// The type that holds the reference to `Self` for the duration of the
59
+ /// invocation of the function that has an `&Self` parameter. This is
60
+ /// required to ensure that the lifetimes don't persist beyond one function
61
+ /// call, and so that they remain anonymous.
35
62
type Anchor : Deref < Target =Self > ;
63
+
64
+ /// Recover a `Self::Anchor` from `Self::Abi`.
65
+ ///
66
+ /// # Safety
67
+ ///
68
+ /// Same as `FromWasmAbi::from_abi`.
36
69
unsafe fn ref_from_abi ( js : Self :: Abi , extra : & mut Stack ) -> Self :: Anchor ;
37
70
}
38
71
@@ -142,7 +175,7 @@ impl IntoWasmAbi for char {
142
175
143
176
impl FromWasmAbi for char {
144
177
type Abi = u32 ;
145
- unsafe fn from_abi ( js : u32 , _extra : & mut Stack ) -> char {
178
+ unsafe fn from_abi ( js : u32 , _extra : & mut Stack ) -> char {
146
179
char:: from_u32_unchecked ( js)
147
180
}
148
181
}
@@ -539,4 +572,4 @@ stack_closures! {
539
572
( A B C D E )
540
573
( A B C D E F )
541
574
( A B C D E F G )
542
- }
575
+ }
0 commit comments