pushwire-client 0.1.1

Generic multiplexed push client with WebSocket and SSE transports
Documentation
use pushwire_core::{ChannelKind, Frame};

/// Handler for inbound frames on a specific channel.
///
/// Implement this trait to receive and process frames for a given channel.
/// Register with [`PushClient::on`](crate::PushClient::on) before connecting.
pub trait ChannelReceiver<C: ChannelKind>: Send + Sync + 'static {
    /// Called when a frame arrives on the registered channel.
    fn on_frame(&self, frame: Frame<C>);

    /// Called when the channel's replay buffer catches up after reconnect.
    /// Default implementation does nothing.
    fn on_replay_complete(&self, _channel: C, _from_cursor: u64, _to_cursor: u64) {}
}

/// Blanket implementation for closures.
impl<C, F> ChannelReceiver<C> for F
where
    C: ChannelKind,
    F: Fn(Frame<C>) + Send + Sync + 'static,
{
    fn on_frame(&self, frame: Frame<C>) {
        (self)(frame)
    }
}