rustzmq2 0.1.0

A native async Rust implementation of ZeroMQ
Documentation
//! Runtime-neutral TCP type aliases.
//!
//! `tokio` and `smol` are mutually exclusive at compile time. This module
//! re-exports the active runtime's `TcpStream` / `TcpListener` under stable
//! names so the rest of the transport layer doesn't have to branch on
//! runtime features for every type reference.

#[cfg(feature = "tokio")]
pub(crate) use tokio::net::{TcpListener, TcpStream};

#[cfg(all(feature = "smol", not(feature = "tokio")))]
pub(crate) use smol::net::{TcpListener, TcpStream};

/// Convert a `std::net::TcpListener` to the active runtime's listener.
///
/// Tokio requires the std listener to be non-blocking and uses `from_std`;
/// smol's `TcpListener` implements `TryFrom<std::net::TcpListener>` directly.
#[cfg(feature = "tokio")]
pub(crate) fn listener_from_std(l: std::net::TcpListener) -> std::io::Result<TcpListener> {
    TcpListener::from_std(l)
}

#[cfg(all(feature = "smol", not(feature = "tokio")))]
pub(crate) fn listener_from_std(l: std::net::TcpListener) -> std::io::Result<TcpListener> {
    TcpListener::try_from(l)
}