forked from siketyan/stateless-discord-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.rs
35 lines (31 loc) · 806 Bytes
/
lib.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
mod context;
mod discord;
mod error;
mod http;
mod utils;
use cfg_if::cfg_if;
use wasm_bindgen::prelude::*;
use crate::context::Context;
use crate::http::HttpResponse;
cfg_if! {
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
if #[cfg(feature = "wee_alloc")] {
extern crate wee_alloc;
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
}
}
#[wasm_bindgen]
pub fn wasm_main(context: &JsValue) -> JsValue {
JsValue::from_serde(
&(match context.into_serde::<Context>() {
Ok(ctx) => ctx.handle_http_request(),
Err(error) => HttpResponse {
status: 400,
body: error.to_string(),
},
}),
)
.unwrap()
}