wasm_wave/wasm/func.rs
1use std::borrow::Cow;
2
3use crate::wasm::WasmType;
4
5// TODO: Given recent versions of rustc we may want to take a look at changing the returns of boxed
6// iterators to -> impl Iterator
7
8/// The WasmFunc trait may be implemented to represent Wasm func type
9/// signatures to be (de)serialized with WAVE.
10pub trait WasmFunc {
11 /// A type representing types of these params and results.
12 type Type: WasmType;
13
14 /// Returns an iterator of the func's parameter types.
15 fn params(&self) -> Box<dyn Iterator<Item = Self::Type> + '_>;
16
17 /// Returns an iterator of the func's parameter names. Must be the same
18 /// length as the iterator returned by `params` or empty if this WasmFunc
19 /// impl does not support param names.
20 fn param_names(&self) -> Box<dyn Iterator<Item = Cow<'_, str>> + '_> {
21 Box::new(std::iter::empty())
22 }
23
24 /// Returns an iterator of the func's result types.
25 fn results(&self) -> Box<dyn Iterator<Item = Self::Type> + '_>;
26
27 /// Returns an iterator of the func's result names. Must be the same
28 /// length as the iterator returned by `results` or empty if there are no
29 /// named results or if this WasmFunc impl does not support result names.
30 fn result_names(&self) -> Box<dyn Iterator<Item = Cow<'_, str>> + '_> {
31 Box::new(std::iter::empty())
32 }
33}