1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use RpcStreamEvent;
use crateFrameDecodeError;
/// Trait alias for any mutable function or closure that emits a byte slice.
///
/// This trait is used by encoders or stream managers that need to send raw
/// byte payloads over an output channel (e.g., a socket, buffer, or transport).
///
/// The function should emit a complete and valid frame fragment.
/// Typically used as a sink.
/// Trait alias for response handlers that consume [`RpcStreamEvent`]`s.
///
/// Implementors must be `Send` to allow handling in concurrent or async contexts.
/// This is used for registering per-request response callbacks in a client session.
///
/// Each event corresponds to part of an RPC response stream, such as [`RpcStreamEvent::Header`],
/// [`RpcStreamEvent::PayloadChunk`], or [`RpcStreamEvent::End`].
/// Trait alias for handlers that decode and process [`RpcStreamEvent`]s fallibly.
///
/// This trait allows the handler to return a `Result` to signal whether
/// the event was processed successfully or should terminate processing
/// due to an error.
///
/// Used when decoding and interpreting streamed RPC messages.
///
/// Example:
/// ```ignore
/// let decoder = |event: RpcStreamEvent| -> Result<(), FrameDecodeError> {
/// match event {
/// RpcStreamEvent::Header { .. } => Ok(()),
/// _ => Err(FrameDecodeError::CorruptFrame),
/// }
/// };
/// ```