Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/app/builder_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ where
/// The protocol defines hooks for connection setup, frame modification, and
/// command completion. It is wrapped in an [`Arc`] and stored for later use
/// by the connection actor.
///
/// At present, the protocol must use `ProtocolError = ()`. This keeps the
/// protocol object safe for dynamic dispatch, maintains a uniform
/// interface across connections, and avoids leaking application-specific
/// error types into the builder API.
#[must_use]
pub fn with_protocol<P>(self, protocol: P) -> Self
where
Expand Down
6 changes: 6 additions & 0 deletions src/fragment/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//! Unit tests for the fragmentation and reassembly subsystem.
//!
//! Covers `FragmentHeader` field access, `FragmentSeries` ordering and
//! validation, `Fragmenter` splitting and message ID management, and
//! `Reassembler` assembly with size limits and expiry handling.

use std::{
num::NonZeroUsize,
time::{Duration, Instant},
Expand Down
17 changes: 13 additions & 4 deletions src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@ use crate::{
pub struct ConnectionContext;

/// Trait encapsulating protocol-specific logic and callbacks.
///
/// `WireframeProtocol` allows a custom `ProtocolError` type, but
/// [`crate::app::WireframeApp::with_protocol`] currently requires
/// `ProtocolError = ()` so the protocol can be stored behind dynamic dispatch
/// with a uniform interface. This constraint may be relaxed in a future
/// release.
pub trait WireframeProtocol: Send + Sync + 'static {
/// Frame type written to the socket.
type Frame: FrameLike;
/// Custom error type for protocol operations.
///
/// When installed via [`crate::app::WireframeApp::with_protocol`], this
/// must currently be `()`.
type ProtocolError;

/// Called once when a new connection is established. The provided
Expand All @@ -45,10 +54,10 @@ pub trait WireframeProtocol: Send + Sync + 'static {
///
/// impl WireframeProtocol for MyProtocol {
/// type Frame = Vec<u8>;
/// type ProtocolError = String;
/// type ProtocolError = ();
///
/// fn handle_error(&self, error: Self::ProtocolError, _ctx: &mut ConnectionContext) {
/// tracing::error!(error = %error, "protocol error");
/// fn handle_error(&self, _error: Self::ProtocolError, _ctx: &mut ConnectionContext) {
/// tracing::error!("protocol error");
/// // Custom handling here
/// }
/// }
Expand Down Expand Up @@ -81,7 +90,7 @@ pub trait WireframeProtocol: Send + Sync + 'static {
///
/// impl WireframeProtocol for MyProtocol {
/// type Frame = Vec<u8>;
/// type ProtocolError = String;
/// type ProtocolError = ();
///
/// fn on_eof(&self, error: &EofError, partial_data: &[u8], _ctx: &mut ConnectionContext) {
/// match error {
Expand Down
Loading