Files
wasmtime/tests/all/import_indexes.rs
Alex Crichton b0939f6626 Remove explicit S type parameters (#5275)
* Remove explicit `S` type parameters

This commit removes the explicit `S` type parameter on `Func::typed` and
`Instance::get_typed_func`. Historical versions of Rust required that
this be a type parameter but recent rustcs support a mixture of explicit
type parameters and `impl Trait`. This removes, at callsites, a
superfluous `, _` argument which otherwise never needs specification.

* Fix mdbook examples
2022-11-16 05:04:26 +00:00

51 lines
1.3 KiB
Rust

use wasmtime::*;
#[test]
fn same_import_names_still_distinct() -> anyhow::Result<()> {
const WAT: &str = r#"
(module
(import "" "" (func $a (result i32)))
(import "" "" (func $b (result f32)))
(func (export "foo") (result i32)
call $a
call $b
i32.trunc_f32_u
i32.add)
)
"#;
let mut store = Store::<()>::default();
let module = Module::new(store.engine(), WAT)?;
let imports = [
Func::new(
&mut store,
FuncType::new(None, Some(ValType::I32)),
|_, params, results| {
assert!(params.is_empty());
assert_eq!(results.len(), 1);
results[0] = 1i32.into();
Ok(())
},
)
.into(),
Func::new(
&mut store,
FuncType::new(None, Some(ValType::F32)),
|_, params, results| {
assert!(params.is_empty());
assert_eq!(results.len(), 1);
results[0] = 2.0f32.into();
Ok(())
},
)
.into(),
];
let instance = Instance::new(&mut store, &module, &imports)?;
let func = instance.get_typed_func::<(), i32>(&mut store, "foo")?;
let result = func.call(&mut store, ())?;
assert_eq!(result, 3);
Ok(())
}