1use crate::*;
2
3#[derive(Clone, Debug)]
4pub struct Function<'a> {
5 pub name: String,
6 pub body: Builder<'a>,
7 pub locals: Vec<ValType>,
8 pub type_index: FunctionTypeIndex,
9 pub index: u32,
10 pub export: Option<String>,
11}
12
13impl<'a> Function<'a> {
14 pub fn push(&mut self, expr: impl Expr<'a>) -> &mut Self {
15 self.body.push(expr);
16 self
17 }
18
19 pub fn export(&mut self, name: impl Into<String>) -> &mut Self {
20 self.export = Some(name.into());
21 self
22 }
23
24 pub fn builder(&mut self) -> &mut Builder<'a> {
25 &mut self.body
26 }
27
28 pub fn with_builder(&mut self, f: impl FnOnce(&mut Builder)) -> &mut Self {
29 f(&mut self.body);
30 self
31 }
32
33 pub fn index(&self) -> FunctionIndex {
34 FunctionIndex::from(self.index)
35 }
36}