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 hook handlers 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.
Source§impl<B> WebSocketConfig<B>where
B: BroadcastTypeTrait,
impl<B> WebSocketConfig<B>where
B: BroadcastTypeTrait,
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 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 set_connected_hook<S>(self) -> WebSocketConfig<B>where
S: ServerHook,
pub fn set_connected_hook<S>(self) -> WebSocketConfig<B>where
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) -> WebSocketConfig<B>where
S: ServerHook,
pub fn set_request_hook<S>(self) -> WebSocketConfig<B>where
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) -> WebSocketConfig<B>where
S: ServerHook,
pub fn set_sended_hook<S>(self) -> WebSocketConfig<B>where
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) -> WebSocketConfig<B>where
S: ServerHook,
pub fn set_closed_hook<S>(self) -> WebSocketConfig<B>where
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,
) -> &Arc<dyn Fn(&Context) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>
pub fn get_connected_hook( &self, ) -> &Arc<dyn Fn(&Context) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>
Retrieves a reference to the connected hook handler.
§Returns
&ServerHookHandler- A reference to the connected hook handler.
Sourcepub fn get_request_hook(
&self,
) -> &Arc<dyn Fn(&Context) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>
pub fn get_request_hook( &self, ) -> &Arc<dyn Fn(&Context) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>
Retrieves a reference to the request hook handler.
§Returns
&ServerHookHandler- A reference to the request hook handler.
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 types that do nothing.
§Type Parameters
B: The type parameter forWebSocketConfig, which must implementBroadcastTypeTrait.
Source§fn default() -> WebSocketConfig<B>
fn default() -> WebSocketConfig<B>
Auto Trait Implementations§
impl<B> Freeze for WebSocketConfig<B>where
B: Freeze,
impl<B> !RefUnwindSafe for WebSocketConfig<B>
impl<B> Send for WebSocketConfig<B>where
B: Send,
impl<B> Sync for WebSocketConfig<B>where
B: Sync,
impl<B> Unpin for WebSocketConfig<B>where
B: Unpin,
impl<B> !UnwindSafe for WebSocketConfig<B>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more