naia_socket_shared/
lib.rs

1//! # Naia Socket Shared
2//! Common data types shared between Naia Server Socket & Naia Client Socket
3
4#![deny(
5    trivial_casts,
6    trivial_numeric_casts,
7    unstable_features,
8    unused_import_braces,
9    unused_qualifications
10)]
11
12#[macro_use]
13extern crate cfg_if;
14
15/// Logic shared between client & server sockets related to simulating network
16/// conditions
17pub mod link_condition_logic;
18
19mod backends;
20mod identity_token;
21mod link_conditioner_config;
22mod socket_config;
23mod time_queue;
24mod url_parse;
25
26pub use backends::{Instant, Random};
27pub use identity_token::*;
28pub use link_conditioner_config::LinkConditionerConfig;
29pub use socket_config::SocketConfig;
30pub use time_queue::TimeQueue;
31pub use url_parse::{parse_server_url, url_to_socket_addr};
32
33#[derive(Debug, Eq, PartialEq)]
34pub struct ChannelClosedError<T>(pub T);
35
36impl<T: std::fmt::Debug> std::error::Error for ChannelClosedError<T> {}
37
38impl<T> std::fmt::Display for ChannelClosedError<T> {
39    fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40        write!(fmt, "channel closed")
41    }
42}
43
44cfg_if! {
45    if #[cfg(all(target_arch = "wasm32", feature = "wbindgen", feature = "mquad"))]
46    {
47        // Use both protocols...
48        compile_error!("wasm target for 'naia_socket_shared' crate requires either the 'wbindgen' OR 'mquad' feature to be enabled, you must pick one.");
49    }
50    else if #[cfg(all(target_arch = "wasm32", not(feature = "wbindgen"), not(feature = "mquad")))]
51    {
52        // Use no protocols...
53        compile_error!("wasm target for 'naia_socket_shared' crate requires either the 'wbindgen' or 'mquad' feature to be enabled, you must pick one.");
54    }
55}