pushwire_client/dispatch.rs
1use pushwire_core::{ChannelKind, Frame};
2
3/// Handler for inbound frames on a specific channel.
4///
5/// Implement this trait to receive and process frames for a given channel.
6/// Register with [`PushClient::on`](crate::PushClient::on) before connecting.
7pub trait ChannelReceiver<C: ChannelKind>: Send + Sync + 'static {
8 /// Called when a frame arrives on the registered channel.
9 fn on_frame(&self, frame: Frame<C>);
10
11 /// Called when the channel's replay buffer catches up after reconnect.
12 /// Default implementation does nothing.
13 fn on_replay_complete(&self, _channel: C, _from_cursor: u64, _to_cursor: u64) {}
14}
15
16/// Blanket implementation for closures.
17impl<C, F> ChannelReceiver<C> for F
18where
19 C: ChannelKind,
20 F: Fn(Frame<C>) + Send + Sync + 'static,
21{
22 fn on_frame(&self, frame: Frame<C>) {
23 (self)(frame)
24 }
25}