#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FeatureSet {
pub native: bool,
pub wasm: bool,
pub client: bool,
pub server: bool,
pub websocket_transport: bool,
pub quic_transport: bool,
pub hybrid_transport: bool,
pub gzip_compression: bool,
pub aes_256_gcm_encryption: bool,
pub tcp_transport: bool,
}
impl FeatureSet {
pub const fn current() -> Self {
let native = cfg!(not(target_arch = "wasm32"));
let wasm = cfg!(target_arch = "wasm32");
let client = cfg!(feature = "client");
let server = cfg!(all(feature = "server", not(target_arch = "wasm32")));
let websocket_transport = cfg!(feature = "websocket");
let quic_transport = cfg!(all(feature = "quic", not(target_arch = "wasm32")));
let tcp_transport = cfg!(all(feature = "tcp", not(target_arch = "wasm32")));
let hybrid_transport = cfg!(all(
feature = "websocket",
feature = "quic",
not(target_arch = "wasm32")
));
Self {
native,
wasm,
client,
server,
websocket_transport,
quic_transport,
hybrid_transport,
gzip_compression: cfg!(feature = "compression-gzip"),
aes_256_gcm_encryption: cfg!(feature = "encryption-aes-gcm"),
tcp_transport,
}
}
}
#[cfg(test)]
mod tests {
use super::FeatureSet;
#[test]
fn current_feature_set_matches_compile_time_cfg() {
let features = FeatureSet::current();
assert_eq!(features.native, cfg!(not(target_arch = "wasm32")));
assert_eq!(features.wasm, cfg!(target_arch = "wasm32"));
assert_eq!(features.client, cfg!(feature = "client"));
assert_eq!(
features.server,
cfg!(all(feature = "server", not(target_arch = "wasm32")))
);
assert_eq!(features.websocket_transport, cfg!(feature = "websocket"));
assert_eq!(
features.quic_transport,
cfg!(all(feature = "quic", not(target_arch = "wasm32")))
);
assert_eq!(
features.hybrid_transport,
cfg!(all(
feature = "websocket",
feature = "quic",
not(target_arch = "wasm32")
))
);
assert_eq!(
features.gzip_compression,
cfg!(feature = "compression-gzip")
);
assert_eq!(
features.aes_256_gcm_encryption,
cfg!(feature = "encryption-aes-gcm")
);
assert_eq!(
features.tcp_transport,
cfg!(all(feature = "tcp", not(target_arch = "wasm32")))
);
}
}