pub struct WebSocketConfig<B>where
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 implementBroadcastTypeTrait
.
Implementations§
Source§impl<B> WebSocketConfig<B>where
B: BroadcastTypeTrait,
impl<B> WebSocketConfig<B>where
B: BroadcastTypeTrait,
Sourcepub fn new() -> WebSocketConfig<B>
pub fn new() -> WebSocketConfig<B>
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) -> WebSocketConfig<B>
pub fn set_buffer_size(self, buffer_size: usize) -> WebSocketConfig<B>
Sourcepub fn set_capacity(self, capacity: usize) -> WebSocketConfig<B>
pub fn set_capacity(self, capacity: usize) -> WebSocketConfig<B>
Sourcepub fn set_context(self, context: Context) -> WebSocketConfig<B>
pub fn set_context(self, context: Context) -> WebSocketConfig<B>
Sourcepub fn set_broadcast_type(
self,
broadcast_type: BroadcastType<B>,
) -> WebSocketConfig<B>
pub fn set_broadcast_type( self, broadcast_type: BroadcastType<B>, ) -> WebSocketConfig<B>
Sourcepub fn set_request_hook<F, Fut>(self, hook: F) -> WebSocketConfig<B>
pub fn set_request_hook<F, Fut>(self, hook: F) -> WebSocketConfig<B>
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 beFn(Context) -> Fut + Send + Sync + 'static
.Fut
: The future returned by the function, which must beFuture<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) -> WebSocketConfig<B>
pub fn set_sended_hook<F, Fut>(self, hook: F) -> WebSocketConfig<B>
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 beFn(Context) -> Fut + Send + Sync + 'static
.Fut
: The future returned by the function, which must beFuture<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) -> WebSocketConfig<B>
pub fn set_closed_hook<F, Fut>(self, hook: F) -> WebSocketConfig<B>
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 beFn(Context) -> Fut + Send + Sync + 'static
.Fut
: The future returned by the function, which must beFuture<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) -> usize
pub fn get_capacity(&self) -> usize
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,
) -> &Arc<dyn FnContextPinBoxSendSync<(), Output = Pin<Box<dyn Future<Output = ()> + Send>>>>
pub fn get_request_hook( &self, ) -> &Arc<dyn FnContextPinBoxSendSync<(), Output = Pin<Box<dyn Future<Output = ()> + Send>>>>
Retrieves a reference to the request hook function.
§Returns
&ArcFnContextPinBoxSendSync<()>
- A reference to the request hook.
Trait Implementations§
Source§impl<B> Clone for WebSocketConfig<B>where
B: Clone + BroadcastTypeTrait,
impl<B> Clone for WebSocketConfig<B>where
B: Clone + BroadcastTypeTrait,
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> Default for WebSocketConfig<B>where
B: BroadcastTypeTrait,
Implements the Default
trait for WebSocketConfig
.
impl<B> Default for WebSocketConfig<B>where
B: BroadcastTypeTrait,
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 forWebSocketConfig
, which must implementBroadcastTypeTrait
.