pub struct Function<'a> {
pub name: String,
pub body: Builder<'a>,
pub locals: Vec<ValType>,
pub type_index: FunctionTypeIndex,
pub index: u32,
pub export: Option<String>,
}
Fields§
§name: String
§body: Builder<'a>
§locals: Vec<ValType>
§type_index: FunctionTypeIndex
§index: u32
§export: Option<String>
Implementations§
Source§impl<'a> Function<'a>
impl<'a> Function<'a>
Sourcepub fn push(&mut self, expr: impl Expr<'a>) -> &mut Self
pub fn push(&mut self, expr: impl Expr<'a>) -> &mut Self
Examples found in repository?
examples/gc.rs (line 85)
71fn main() -> anyhow::Result<()> {
72 let mut module = Module::new();
73 let field = field_type(StorageType::Val(ValType::I32), true);
74 let idx = module.struct_type([field, field]);
75 let t = ValType::Ref(RefType {
76 nullable: false,
77 heap_type: HeapType::Concrete(idx.index()),
78 });
79
80 let mut locals = TypeList::new();
81 let a = locals.push(t);
82 let b = locals.push(t);
83 module
84 .func("add", locals, [], [])
85 .push(Add(a, b, idx))
86 .export("add");
87
88 let mut locals = TypeList::new();
89 let a = locals.push(t);
90 module
91 .func("sum", locals, [ValType::I32], [])
92 .push(Sum(a, idx))
93 .export("sum")
94 .index();
95
96 let mut locals = TypeList::new();
97 let a = locals.push(ValType::I32);
98 let b = locals.push(ValType::I32);
99 module
100 .func("init", locals, [t], [])
101 .push(Init(a, b, idx))
102 .export("init");
103
104 module.save("gc.wasm")?;
105 Ok(())
106}
Sourcepub fn export(&mut self, name: impl Into<String>) -> &mut Self
pub fn export(&mut self, name: impl Into<String>) -> &mut Self
Examples found in repository?
examples/gc.rs (line 86)
71fn main() -> anyhow::Result<()> {
72 let mut module = Module::new();
73 let field = field_type(StorageType::Val(ValType::I32), true);
74 let idx = module.struct_type([field, field]);
75 let t = ValType::Ref(RefType {
76 nullable: false,
77 heap_type: HeapType::Concrete(idx.index()),
78 });
79
80 let mut locals = TypeList::new();
81 let a = locals.push(t);
82 let b = locals.push(t);
83 module
84 .func("add", locals, [], [])
85 .push(Add(a, b, idx))
86 .export("add");
87
88 let mut locals = TypeList::new();
89 let a = locals.push(t);
90 module
91 .func("sum", locals, [ValType::I32], [])
92 .push(Sum(a, idx))
93 .export("sum")
94 .index();
95
96 let mut locals = TypeList::new();
97 let a = locals.push(ValType::I32);
98 let b = locals.push(ValType::I32);
99 module
100 .func("init", locals, [t], [])
101 .push(Init(a, b, idx))
102 .export("init");
103
104 module.save("gc.wasm")?;
105 Ok(())
106}
pub fn builder(&mut self) -> &mut Builder<'a>
pub fn with_builder(&mut self, f: impl FnOnce(&mut Builder<'_>)) -> &mut Self
Sourcepub fn index(&self) -> FunctionIndex
pub fn index(&self) -> FunctionIndex
Examples found in repository?
examples/gc.rs (line 94)
71fn main() -> anyhow::Result<()> {
72 let mut module = Module::new();
73 let field = field_type(StorageType::Val(ValType::I32), true);
74 let idx = module.struct_type([field, field]);
75 let t = ValType::Ref(RefType {
76 nullable: false,
77 heap_type: HeapType::Concrete(idx.index()),
78 });
79
80 let mut locals = TypeList::new();
81 let a = locals.push(t);
82 let b = locals.push(t);
83 module
84 .func("add", locals, [], [])
85 .push(Add(a, b, idx))
86 .export("add");
87
88 let mut locals = TypeList::new();
89 let a = locals.push(t);
90 module
91 .func("sum", locals, [ValType::I32], [])
92 .push(Sum(a, idx))
93 .export("sum")
94 .index();
95
96 let mut locals = TypeList::new();
97 let a = locals.push(ValType::I32);
98 let b = locals.push(ValType::I32);
99 module
100 .func("init", locals, [t], [])
101 .push(Init(a, b, idx))
102 .export("init");
103
104 module.save("gc.wasm")?;
105 Ok(())
106}
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Function<'a>
impl<'a> RefUnwindSafe for Function<'a>
impl<'a> Send for Function<'a>
impl<'a> Sync for Function<'a>
impl<'a> Unpin for Function<'a>
impl<'a> UnwindSafe for Function<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more