pub struct WebSocketConfig<'a, 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<'a, B> WebSocketConfig<'a, B>where
B: BroadcastTypeTrait,
impl<'a, B> WebSocketConfig<'a, B>where
B: BroadcastTypeTrait,
Source§impl<'a, B> WebSocketConfig<'a, B>where
B: BroadcastTypeTrait,
impl<'a, B> WebSocketConfig<'a, B>where
B: BroadcastTypeTrait,
Sourcepub fn set_capacity(self, capacity: usize) -> WebSocketConfig<'a, B>
pub fn set_capacity(self, capacity: usize) -> WebSocketConfig<'a, B>
Sourcepub fn set_context(self, context: &'a mut Context) -> WebSocketConfig<'a, B>
pub fn set_context(self, context: &'a mut Context) -> WebSocketConfig<'a, B>
Sourcepub fn set_broadcast_type(
self,
broadcast_type: BroadcastType<B>,
) -> WebSocketConfig<'a, B>
pub fn set_broadcast_type( self, broadcast_type: BroadcastType<B>, ) -> WebSocketConfig<'a, B>
Sourcepub fn get_context(&mut self) -> &mut Context
pub fn get_context(&mut self) -> &mut Context
Retrieves a reference to the context associated with this configuration.
§Returns
&mut Context- A reference to the context object.
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<'a, B>where
S: ServerHook,
pub fn set_connected_hook<S>(self) -> WebSocketConfig<'a, 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<'a, B>where
S: ServerHook,
pub fn set_request_hook<S>(self) -> WebSocketConfig<'a, 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<'a, B>where
S: ServerHook,
pub fn set_sended_hook<S>(self) -> WebSocketConfig<'a, 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<'a, B>where
S: ServerHook,
pub fn set_closed_hook<S>(self) -> WebSocketConfig<'a, 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(&mut Context) -> Pin<Box<dyn Future<Output = ()> + Send>> + Sync + Send>
pub fn get_connected_hook( &self, ) -> &Arc<dyn Fn(&mut Context) -> Pin<Box<dyn Future<Output = ()> + Send>> + Sync + Send>
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(&mut Context) -> Pin<Box<dyn Future<Output = ()> + Send>> + Sync + Send>
pub fn get_request_hook( &self, ) -> &Arc<dyn Fn(&mut Context) -> Pin<Box<dyn Future<Output = ()> + Send>> + Sync + Send>
Retrieves a reference to the request hook handler.
§Returns
&ServerHookHandler- A reference to the request hook handler.
Auto Trait Implementations§
impl<'a, B> Freeze for WebSocketConfig<'a, B>where
B: Freeze,
impl<'a, B> !RefUnwindSafe for WebSocketConfig<'a, B>
impl<'a, B> Send for WebSocketConfig<'a, B>where
B: Send,
impl<'a, B> Sync for WebSocketConfig<'a, B>where
B: Sync,
impl<'a, B> Unpin for WebSocketConfig<'a, B>where
B: Unpin,
impl<'a, B> UnsafeUnpin for WebSocketConfig<'a, B>where
B: UnsafeUnpin,
impl<'a, B> !UnwindSafe for WebSocketConfig<'a, 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> 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