pub struct WebSocketConfig<B: BroadcastTypeTrait> { /* private fields */ }Expand description
Configuration for a WebSocket connection.
This struct encapsulates all necessary parameters for setting up and managing a WebSocket connection, including context, buffer sizes, capacity, broadcast type, and hook handlers for different lifecycle events.
§Type Parameters
B: The type used for broadcast keys, which must implementBroadcastTypeTrait.
Implementations§
Source§impl<B: BroadcastTypeTrait> WebSocketConfig<B>
impl<B: BroadcastTypeTrait> WebSocketConfig<B>
Source§impl<B: BroadcastTypeTrait> WebSocketConfig<B>
impl<B: BroadcastTypeTrait> WebSocketConfig<B>
Sourcepub fn set_buffer_size(self, buffer_size: usize) -> Self
pub fn set_buffer_size(self, buffer_size: usize) -> Self
Sourcepub fn set_capacity(self, capacity: Capacity) -> Self
pub fn set_capacity(self, capacity: Capacity) -> Self
Sourcepub fn set_context(self, context: Context) -> Self
pub fn set_context(self, context: Context) -> Self
Sourcepub fn set_broadcast_type(self, broadcast_type: BroadcastType<B>) -> Self
pub fn set_broadcast_type(self, broadcast_type: BroadcastType<B>) -> Self
Sourcepub fn get_context(&self) -> &Context
pub fn get_context(&self) -> &Context
Retrieves a reference to the context associated with this configuration.
§Returns
&Context- A reference to the context object.
Sourcepub fn get_buffer_size(&self) -> usize
pub fn get_buffer_size(&self) -> usize
Retrieves the buffer size configured for the WebSocket connection.
§Returns
usize- The buffer size in bytes.
Sourcepub fn get_capacity(&self) -> Capacity
pub fn get_capacity(&self) -> Capacity
Sourcepub fn get_broadcast_type(&self) -> &BroadcastType<B>
pub fn get_broadcast_type(&self) -> &BroadcastType<B>
Retrieves a reference to the broadcast type configured for this WebSocket.
§Returns
&BroadcastType<B>- A reference to the broadcast type object.
Sourcepub fn set_connected_hook<S>(self) -> Selfwhere
S: ServerHook,
pub fn set_connected_hook<S>(self) -> Selfwhere
S: ServerHook,
Sets the connected hook handler.
This hook is executed when the WebSocket connection is established.
§Type Parameters
S: The hook type, which must implementServerHook.
§Returns
The modified WebSocketConfig instance.
§Examples
struct MyConnectedHook;
impl ServerHook for MyConnectedHook {
async fn new(_ctx: &Context) -> Self { Self }
async fn handle(self, ctx: &Context) { /* ... */ }
}
let config = WebSocketConfig::new()
.set_connected_hook::<MyConnectedHook>();Sourcepub fn set_request_hook<S>(self) -> Selfwhere
S: ServerHook,
pub fn set_request_hook<S>(self) -> Selfwhere
S: ServerHook,
Sets the request hook handler.
This hook is executed when a new request is received on the WebSocket.
§Type Parameters
S: The hook type, which must implementServerHook.
§Returns
The modified WebSocketConfig instance.
§Examples
struct MyRequestHook;
impl ServerHook for MyRequestHook {
async fn new(_ctx: &Context) -> Self { Self }
async fn handle(self, ctx: &Context) { /* ... */ }
}
let config = WebSocketConfig::new()
.set_request_hook::<MyRequestHook>();Sourcepub fn set_sended_hook<S>(self) -> Selfwhere
S: ServerHook,
pub fn set_sended_hook<S>(self) -> Selfwhere
S: ServerHook,
Sets the sended hook handler.
This hook is executed after a message has been successfully sent over the WebSocket.
§Type Parameters
S: The hook type, which must implementServerHook.
§Returns
The modified WebSocketConfig instance.
§Examples
struct MySendedHook;
impl ServerHook for MySendedHook {
async fn new(_ctx: &Context) -> Self { Self }
async fn handle(self, ctx: &Context) { /* ... */ }
}
let config = WebSocketConfig::new()
.set_sended_hook::<MySendedHook>();Sourcepub fn set_closed_hook<S>(self) -> Selfwhere
S: ServerHook,
pub fn set_closed_hook<S>(self) -> Selfwhere
S: ServerHook,
Sets the closed hook handler.
This hook is executed when the WebSocket connection is closed.
§Type Parameters
S: The hook type, which must implementServerHook.
§Returns
The modified WebSocketConfig instance.
§Examples
struct MyClosedHook;
impl ServerHook for MyClosedHook {
async fn new(_ctx: &Context) -> Self { Self }
async fn handle(self, ctx: &Context) { /* ... */ }
}
let config = WebSocketConfig::new()
.set_closed_hook::<MyClosedHook>();Sourcepub fn get_connected_hook(&self) -> &ServerHookHandler
pub fn get_connected_hook(&self) -> &ServerHookHandler
Retrieves a reference to the connected hook handler.
§Returns
&ServerHookHandler- A reference to the connected hook handler.
Sourcepub fn get_request_hook(&self) -> &ServerHookHandler
pub fn get_request_hook(&self) -> &ServerHookHandler
Retrieves a reference to the request hook handler.
§Returns
&ServerHookHandler- A reference to the request hook handler.
Sourcepub fn get_sended_hook(&self) -> &ServerHookHandler
pub fn get_sended_hook(&self) -> &ServerHookHandler
Retrieves a reference to the sended hook handler.
§Returns
&ServerHookHandler- A reference to the sended hook handler.
Sourcepub fn get_closed_hook(&self) -> &ServerHookHandler
pub fn get_closed_hook(&self) -> &ServerHookHandler
Retrieves a reference to the closed hook handler.
§Returns
&ServerHookHandler- A reference to the closed hook handler.
Trait Implementations§
Source§impl<B: Clone + BroadcastTypeTrait> Clone for WebSocketConfig<B>
impl<B: Clone + BroadcastTypeTrait> Clone for WebSocketConfig<B>
Source§fn clone(&self) -> WebSocketConfig<B>
fn clone(&self) -> WebSocketConfig<B>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<B: BroadcastTypeTrait> Default for WebSocketConfig<B>
Implements the Default trait for WebSocketConfig.
impl<B: BroadcastTypeTrait> Default for WebSocketConfig<B>
Implements the Default trait for WebSocketConfig.
Provides a default configuration for WebSocket connections, including default hook types that do nothing.
§Type Parameters
B: The type parameter forWebSocketConfig, which must implementBroadcastTypeTrait.