flare_core/common/
features.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub struct FeatureSet {
10 pub native: bool,
12 pub wasm: bool,
14 pub client: bool,
16 pub server: bool,
18 pub websocket_transport: bool,
20 pub quic_transport: bool,
22 pub hybrid_transport: bool,
24 pub gzip_compression: bool,
26 pub aes_256_gcm_encryption: bool,
28 pub tcp_transport: bool,
30}
31
32impl FeatureSet {
33 pub const fn current() -> Self {
35 let native = cfg!(not(target_arch = "wasm32"));
36 let wasm = cfg!(target_arch = "wasm32");
37 let client = cfg!(feature = "client");
38 let server = cfg!(all(feature = "server", not(target_arch = "wasm32")));
39 let websocket_transport = cfg!(feature = "websocket");
40 let quic_transport = cfg!(all(feature = "quic", not(target_arch = "wasm32")));
41 let tcp_transport = cfg!(all(feature = "tcp", not(target_arch = "wasm32")));
42 let hybrid_transport = cfg!(all(
43 feature = "websocket",
44 feature = "quic",
45 not(target_arch = "wasm32")
46 ));
47
48 Self {
49 native,
50 wasm,
51 client,
52 server,
53 websocket_transport,
54 quic_transport,
55 hybrid_transport,
56 gzip_compression: cfg!(feature = "compression-gzip"),
57 aes_256_gcm_encryption: cfg!(feature = "encryption-aes-gcm"),
58 tcp_transport,
59 }
60 }
61}
62
63#[cfg(test)]
64mod tests {
65 use super::FeatureSet;
66
67 #[test]
68 fn current_feature_set_matches_compile_time_cfg() {
69 let features = FeatureSet::current();
70
71 assert_eq!(features.native, cfg!(not(target_arch = "wasm32")));
72 assert_eq!(features.wasm, cfg!(target_arch = "wasm32"));
73 assert_eq!(features.client, cfg!(feature = "client"));
74 assert_eq!(
75 features.server,
76 cfg!(all(feature = "server", not(target_arch = "wasm32")))
77 );
78 assert_eq!(features.websocket_transport, cfg!(feature = "websocket"));
79 assert_eq!(
80 features.quic_transport,
81 cfg!(all(feature = "quic", not(target_arch = "wasm32")))
82 );
83 assert_eq!(
84 features.hybrid_transport,
85 cfg!(all(
86 feature = "websocket",
87 feature = "quic",
88 not(target_arch = "wasm32")
89 ))
90 );
91 assert_eq!(
92 features.gzip_compression,
93 cfg!(feature = "compression-gzip")
94 );
95 assert_eq!(
96 features.aes_256_gcm_encryption,
97 cfg!(feature = "encryption-aes-gcm")
98 );
99 assert_eq!(
100 features.tcp_transport,
101 cfg!(all(feature = "tcp", not(target_arch = "wasm32")))
102 );
103 }
104}