moqtap_proxy/observer.rs
1//! Proxy observer trait for receiving proxy events.
2
3use crate::event::ProxyEvent;
4
5/// Observer that receives events from the proxy's inline parser.
6///
7/// Implementations must be `Send + Sync` because the observer is shared
8/// across multiple forwarding tasks. Use interior mutability (e.g.,
9/// `Mutex`, `mpsc::Sender`) if you need mutable state.
10pub trait ProxyObserver: Send + Sync {
11 /// Called for each event emitted by the proxy.
12 fn on_event(&self, event: &ProxyEvent);
13
14 /// Whether this observer cares about events.
15 ///
16 /// When this returns `false`, the proxy can skip constructing
17 /// `ProxyEvent` values and, in some cases, skip parsing entirely —
18 /// turning the proxy into a true byte-for-byte pass-through. Default
19 /// is `true` (preserve existing behavior for custom observers).
20 fn wants_events(&self) -> bool {
21 true
22 }
23}
24
25/// A no-op observer that discards all events.
26pub struct NoOpProxyObserver;
27
28impl ProxyObserver for NoOpProxyObserver {
29 fn on_event(&self, _event: &ProxyEvent) {}
30
31 fn wants_events(&self) -> bool {
32 false
33 }
34}