Closed callmeclover closed 6 months ago
I don't think this is the right place to ask, this is not a problem in Chrono. Maybe wasm_bindgen
can't derive a binding because of the Option
or because of the DateTime
? I suggest opening in issue in their repo.
I suppose the value must be converted to a js_sys::Date
type. Chrono provides a From
implementation.
I suppose the value must be converted to a js_sys::Date
type. Chrono provides a From
implementation.
Error message
``` error[E0277]: the trait bound `DateTimelib.rs
```rust mod model; use model::*; use wasm_bindgen::prelude::*; use web_sys::{ window, Element }; use ewebsock::{ Options, WsEvent, WsMessage::Text }; use urlencoding::encode; extern crate console_error_panic_hook; use std::panic; use web_sys_main_loop::FrameState; #[wasm_bindgen(start)] fn start_wasm() { panic::set_hook(Box::new(console_error_panic_hook::hook)); let window = window().expect("no global `window` exists"); let document = window.document().expect("should have a document on window"); let body = document.body().expect("document should have a body"); let elem = document.create_element("p").unwrap(); elem.set_text_content(Some("WASM module loaded!")); body.append_child(&elem).unwrap(); } #[wasm_bindgen] pub fn main() { let window = window().expect("no global `window` exists"); let document = window.document().expect("should have a document on window"); let body = document.body().expect("document should have a body"); let (mut sender, receiver) = ewebsock ::connect("unnecessary to be here", Options::default()) .expect(""); sender.send( ewebsock::WsMessage::Text( serde_json ::to_string( &(MessageSent { user: "test42".to_string(), msg: "hello".to_string(), time: None, }) ) .unwrap() ) ); web_sys_main_loop::start(&window, move |_frame_state: FrameState| { while let Some(WsEvent::Message(Text(event))) = receiver.try_recv() { match serde_json::from_str::model.rs
```rust use serde::{ Deserialize, Serialize }; use chrono::{ DateTime, Utc }; use wasm_bindgen::prelude::*; #[derive(Serialize, Deserialize, Debug, Clone)] #[serde(untagged)] pub enum MessageTypes { MessageSent(MessageSent), RetrieveMessages(RetrieveMessages), UserJoin(UserJoin), UserLeft(UserLeft), } #[derive(Serialize, Deserialize, Debug, Clone)] #[wasm_bindgen] pub struct MessageSent { pub msg: String, pub user: String, #[serde(skip_serializing)] pub time: OptionCargo.toml
```toml [package] name = "rwst" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] crate-type = ["cdylib"] [dependencies] wasm-bindgen = "0.2.92" ewebsock = "0.5.0" chrono = { version = "0.4.37", features = ["serde", "wasmbind"] } serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.115" urlencoding = "2.1.3" web-sys-main-loop = "0.1.8" console_error_panic_hook = "0.1.7" [dependencies.web-sys] version = "0.3.4" features = [ 'Document', 'Element', 'HtmlElement', 'Node', 'Window', ] ```Why does this happen? I compile with
wasmbind
explicitly enabled, so I don't know what could be happening here.