-
Notifications
You must be signed in to change notification settings - Fork 279
/
calculator.rs
41 lines (40 loc) · 1.34 KB
/
calculator.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! This file is an example output generated by `worker-codegen` from `wit/calculator.wit`,
//! and is not used by this crate.
mod sys {
use ::wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends = ::worker::js_sys::Object)]
pub type CalculatorSys;
#[wasm_bindgen(method, catch, js_name = "add")]
pub fn add(
this: &CalculatorSys,
a: u32,
b: u32,
) -> std::result::Result<
::worker::js_sys::Promise,
::worker::wasm_bindgen::JsValue,
>;
}
}
#[async_trait::async_trait]
pub trait Calculator {
async fn add(&self, a: u32, b: u32) -> ::worker::Result<u64>;
}
pub struct CalculatorService(::worker::send::SendWrapper<sys::CalculatorSys>);
#[async_trait::async_trait]
impl Calculator for CalculatorService {
async fn add(&self, a: u32, b: u32) -> ::worker::Result<u32> {
let promise = self.0.add(a, b)?;
let fut = ::worker::send::SendFuture::new(
::worker::wasm_bindgen_futures::JsFuture::from(promise),
);
let output = fut.await?;
Ok(::serde_wasm_bindgen::from_value(output)?)
}
}
impl From<::worker::Fetcher> for CalculatorService {
fn from(fetcher: ::worker::Fetcher) -> Self {
Self(::worker::send::SendWrapper::new(fetcher.into_rpc()))
}
}