mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-06-13 07:10:26 +08:00
26 lines
745 B
Rust
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); |