Add an example #[wasmtime] Rust macro (#283)
This commit adds a `wasmtime-rust` crate to the `misc` folder next to the previously added Python extension. The intention is that this showcases loading a WebAssembly file natively in Rust and how with an attribute macro it can feel lightweight in terms of boilerplate. The macro itself is pretty non-featureful today beyond the bare bones to get anything working, but there's all sorts of possibilities like JIT-compiled entry stubs we could eventually do with all the type information!
This commit is contained in:
committed by
Till Schneidereit
parent
54dd085e27
commit
d1b1500d19
@@ -1,3 +1,4 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt;
|
||||
|
||||
/// The set of all possible WebAssembly Interface Types
|
||||
@@ -20,6 +21,17 @@ macro_rules! from {
|
||||
Value::$b(val)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Value> for $a {
|
||||
type Error = failure::Error;
|
||||
|
||||
fn try_from(val: Value) -> Result<$a, Self::Error> {
|
||||
match val {
|
||||
Value::$b(v) => Ok(v),
|
||||
v => failure::bail!("cannot convert {:?} to {}", v, stringify!($a)),
|
||||
}
|
||||
}
|
||||
}
|
||||
)*)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user