doido-cable 0.0.13

Action Cable analogue: channels, broadcasts, Turbo-friendly pub/sub backends for Doido.
Documentation
pub mod cable;
pub mod channel;
pub mod config;
pub mod connection;
#[cfg(feature = "cable-db")]
pub mod db_pubsub;
pub mod heartbeat;
pub mod protocol;
pub mod pubsub;
#[cfg(feature = "cable-redis")]
pub mod redis_pubsub;
pub mod server;
pub mod streams;

pub use cable::Cable;
pub use channel::{Channel, ChannelContext, ChannelName};
pub use config::{build_configured_pubsub, CableConfig};
pub use connection::CableConnection;
pub use server::{handle_socket, route as cable_route, ws_handler, ChannelRegistry};

/// Build the pub/sub backend selected by the `cable` section of
/// `config/<env>.yml` (in-memory when absent), connecting the database for the
/// `db` backend. Pair with [`cable!`] to mount the endpoint:
///
/// ```ignore
/// let pubsub = doido_cable::pubsub_from_config().await?;
/// let app = doido_cable::cable!(pubsub, [ChatChannel]);
/// ```
pub async fn pubsub_from_config() -> doido_core::Result<std::sync::Arc<dyn PubSub>> {
    build_configured_pubsub(&config::load()).await
}
// The `#[channel]` attribute macro. It lives in the macro namespace, so it
// coexists with the `channel` module (type namespace); `channel_macro` is kept
// as an alias for callers that prefer the unambiguous name.
#[cfg(feature = "cable-db")]
pub use db_pubsub::DbPubSub;
pub use doido_cable_macros::channel;
pub use doido_cable_macros::channel as channel_macro;
pub use protocol::{CableFrame, ServerFrame, ServerMessage};
pub use pubsub::{MemoryPubSub, PubSub};
#[cfg(feature = "cable-redis")]
pub use redis_pubsub::RedisPubSub;

/// Build an axum `Router` mounting the cable endpoint (`/cable`) for the given
/// channels over a pub/sub backend (Rails' `mount ActionCable.server`):
///
/// ```ignore
/// let app = doido_cable::cable!(pubsub, [ChatChannel, NotificationsChannel]);
/// // With a configured heartbeat interval:
/// let app = doido_cable::cable!(pubsub, [ChatChannel], heartbeat = cfg.ping_interval);
/// ```
#[macro_export]
macro_rules! cable {
    ($pubsub:expr, [ $($channel:expr),* $(,)? ]) => {{
        let mut __registry = $crate::server::ChannelRegistry::new($pubsub);
        $( __registry.register_channel($channel); )*
        $crate::server::route(::std::sync::Arc::new(__registry))
    }};
    ($pubsub:expr, [ $($channel:expr),* $(,)? ], heartbeat = $heartbeat:expr) => {{
        let mut __registry =
            $crate::server::ChannelRegistry::new($pubsub).with_heartbeat($heartbeat);
        $( __registry.register_channel($channel); )*
        $crate::server::route(::std::sync::Arc::new(__registry))
    }};
}