Files
vscode-extension-samples/wasm-component-model-async/src/lib.rs
2024-05-29 16:13:03 +02:00

26 lines
745 B
Rust

// Use a procedural macro to generate bindings for the world we specified in
// `host.wit`
wit_bindgen::generate!({
// the name of the world in the `*.wit` input file
world: "calculator",
});
struct Calculator;
impl Guest for Calculator {
fn calc(op: Operation) -> u32 {
log(&format!("Starting calculation: {:?}", op));
let result = match op {
Operation::Add(operands) => operands.left + operands.right,
Operation::Sub(operands) => operands.left - operands.right,
Operation::Mul(operands) => operands.left * operands.right,
Operation::Div(operands) => operands.left / operands.right,
};
log(&format!("Finished calculation: {:?}", op));
result
}
}
// Export the Calculator to the extension code.
export!(Calculator);