//! # Hornbeam
//! Hornbeam is a simple WebSocket protocol library. For the client or server crates, check out
//! `hornbeam-client` or `hornbeam-server`.

#![deny(clippy::correctness)]
#![warn(clippy::suspicious)]
#![warn(clippy::style)]
#![warn(clippy::complexity)]
#![deny(clippy::perf)]
#![warn(clippy::pedantic)]
#![warn(clippy::nursery)]
//#![deny(clippy::unwrap_used)]
#![warn(clippy::expect_used)]
//#![deny(missing_docs)]
#![allow(clippy::must_use_candidate)] // This gets annoying

#[allow(unused)]
#[macro_use]
pub(crate) mod logging {
    macro_rules! trace {
        ($($x:tt)*) => (
            #[cfg(feature = "logging")] {
                log::trace!($($x)*)
            }
        )
    }

    macro_rules! debug {
        ($($x:tt)*) => (
            #[cfg(feature = "logging")] {
                log::debug!($($x)*)
            }
        )
    }

    macro_rules! info {
        ($($x:tt)*) => (
            #[cfg(feature = "logging")] {
                log::info!($($x)*)
            }
        )
    }

    macro_rules! warn {
        ($($x:tt)*) => (
            #[cfg(feature = "logging")] {
                log::warn!($($x)*)
            }
        )
    }

    macro_rules! error {
        ($($x:tt)*) => (
            #[cfg(feature = "logging")] {
                log::error!($($x)*)
            }
        )
    }
}

/// Contains the state definitions of the WebSocket state machine
pub mod state;

/// Contains the common code for the client and server handshakes
pub mod handshake_common;

/// Contains the code for the client handshake
pub mod handshake_client;

/// Contains the code for the server handshake
pub mod handshake_server;

/// Contains the generic WebSocket stream implementation, that streams are upgraded into after completing the client or server handshake
pub mod stream;

#[cfg(not(feature = "csprng-rand"))]
compile_error!("You need to select one CSPRNG implementation");

/// Pluggable CSPRNG implementation
#[cfg(feature = "csprng-rand")]
#[path = "random_rand.rs"]
pub mod random;

pub(crate) mod b64;

/// WebSocket frame encoding and decoding
pub mod frame;

/// Adds a generic TryClone method to allow for generalization of it
pub mod splittable;

#[cfg(test)]
pub(crate) mod tests {
    use std::sync::Once;

    static LOG: Once = Once::new();
    pub(crate) fn setup_logger() {
        LOG.call_once(|| simple_logger::init().unwrap());
    }
}