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 various hook functions for different lifecycle events.
§Type Parameters
- B: The type used for broadcast keys, which must implement- BroadcastTypeTrait.
Implementations§
Source§impl<B: BroadcastTypeTrait> WebSocketConfig<B>
 
impl<B: BroadcastTypeTrait> WebSocketConfig<B>
Sourcepub fn new() -> Self
 
pub fn new() -> Self
Creates a new WebSocket configuration with default values.
§Returns
- WebSocketConfig<B>- A new WebSocket configuration instance.
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 set_request_hook<F, Fut>(self, hook: F) -> Self
 
pub fn set_request_hook<F, Fut>(self, hook: F) -> Self
Sets the request hook function.
This hook is executed when a new request is received.
§Type Parameters
- F: The type of the function, which must be- Fn(Context) -> Fut + Send + Sync + 'static.
- Fut: The future returned by the function, which must be- Future<Output = ()> + Send + 'static.
§Arguments
- hook- The function to be used as the request hook.
§Returns
The modified WebSocket configuration instance.
Sourcepub fn set_sended_hook<F, Fut>(self, hook: F) -> Self
 
pub fn set_sended_hook<F, Fut>(self, hook: F) -> Self
Sets the sended hook function.
This hook is executed after a message has been sent.
§Type Parameters
- F: The type of the function, which must be- Fn(Context) -> Fut + Send + Sync + 'static.
- Fut: The future returned by the function, which must be- Future<Output = ()> + Send + 'static.
§Arguments
- hook- The function to be used as the sended hook.
§Returns
The modified WebSocket configuration instance.
Sourcepub fn set_closed_hook<F, Fut>(self, hook: F) -> Self
 
pub fn set_closed_hook<F, Fut>(self, hook: F) -> Self
Sets the closed hook function.
This hook is executed when the WebSocket connection is closed.
§Type Parameters
- F: The type of the function, which must be- Fn(Context) -> Fut + Send + Sync + 'static.
- Fut: The future returned by the function, which must be- Future<Output = ()> + Send + 'static.
§Arguments
- hook- The function to be used as the closed hook.
§Returns
The modified WebSocket configuration instance.
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 get_request_hook(&self) -> &ArcFnContextPinBoxSendSync<()>
 
pub fn get_request_hook(&self) -> &ArcFnContextPinBoxSendSync<()>
Retrieves a reference to the request hook function.
§Returns
- &ArcFnContextPinBoxSendSync<()>- A reference to the request hook.
Sourcepub fn get_sended_hook(&self) -> &ArcFnContextPinBoxSendSync<()>
 
pub fn get_sended_hook(&self) -> &ArcFnContextPinBoxSendSync<()>
Retrieves a reference to the sended hook function.
§Returns
- &ArcFnContextPinBoxSendSync<()>- A reference to the sended hook.
Sourcepub fn get_closed_hook(&self) -> &ArcFnContextPinBoxSendSync<()>
 
pub fn get_closed_hook(&self) -> &ArcFnContextPinBoxSendSync<()>
Retrieves a reference to the closed hook function.
§Returns
- &ArcFnContextPinBoxSendSync<()>- A reference to the closed hook.
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 functions that do nothing.
§Type Parameters
- B: The type parameter for- WebSocketConfig, which must implement- BroadcastTypeTrait.