ws_stream_wasm/
lib.rs

1#![cfg_attr( nightly, feature(doc_cfg) )]
2#![cfg_attr( nightly, cfg_attr( nightly, doc = include_str!("../README.md") ))]
3#![doc = ""] // empty doc line to handle missing doc warning when the feature is missing.
4
5#![ doc    ( html_root_url = "https://docs.rs/ws_stream_wasm"            ) ]
6#![ forbid ( unsafe_code                                                 ) ]
7#![ allow  ( clippy::suspicious_else_formatting, clippy::needless_return ) ]
8
9
10#![ warn
11(
12	missing_debug_implementations ,
13	missing_docs                  ,
14	nonstandard_style             ,
15	rust_2018_idioms              ,
16	trivial_casts                 ,
17	trivial_numeric_casts         ,
18	unused_extern_crates          ,
19	unused_qualifications         ,
20	single_use_lifetimes          ,
21	unreachable_pub               ,
22	variant_size_differences      ,
23)]
24
25
26
27mod error        ;
28mod ws_event     ;
29mod ws_message   ;
30mod ws_meta      ;
31mod ws_state     ;
32mod ws_stream    ;
33mod ws_stream_io ;
34
35pub use
36{
37	error        :: { WsErr               } ,
38	ws_event     :: { WsEvent, CloseEvent } ,
39	ws_message   :: { WsMessage           } ,
40	ws_meta      :: { WsMeta              } ,
41	ws_state     :: { WsState             } ,
42	ws_stream    :: { WsStream            } ,
43	ws_stream_io :: { WsStreamIo          } ,
44};
45
46
47
48mod import
49{
50	pub(crate) use
51	{
52		futures              :: { prelude::{ Stream, Sink }, ready, StreamExt, FutureExt                         } ,
53		std                  :: { io, collections::VecDeque, fmt, task::{ Context, Waker, Poll }, future::Future } ,
54		std                  :: { rc::Rc, cell::{ RefCell }, pin::Pin, convert::{ TryFrom, TryInto }             } ,
55		js_sys               :: { ArrayBuffer, Uint8Array                                                        } ,
56		wasm_bindgen         :: { closure::Closure, JsCast, JsValue, UnwrapThrowExt                              } ,
57		web_sys              :: { *, BinaryType, Blob, WebSocket, CloseEvent as JsCloseEvt, DomException         } ,
58		js_sys               :: { Array                                                                          } ,
59		pharos               :: { SharedPharos, PharErr, Observable, Observe, Filter, ObserveConfig,             } ,
60		wasm_bindgen_futures :: { spawn_local                                                                    } ,
61		async_io_stream      :: { IoStream                                                                       } ,
62		thiserror            :: { Error                                                                          } ,
63		send_wrapper         :: { SendWrapper                                                                    } ,
64	};
65}
66
67
68use import::*;
69
70/// Helper function to reduce code bloat
71//
72pub(crate) fn notify( pharos: SharedPharos<WsEvent>, evt: WsEvent )
73{
74	let notify = async move
75	{
76		pharos.notify( evt ).await
77
78			.map_err( |e| unreachable!( "{:?}", e ) ).unwrap(); // only happens if we closed it.
79	};
80
81	spawn_local( notify );
82}