Skip to main content

WebSocketConfig

Struct WebSocketConfig 

Source
pub struct WebSocketConfig<'a, B: BroadcastTypeTrait> {
    pub stream: &'a mut Stream,
    pub context: &'a mut Context,
    pub capacity: Capacity,
    pub broadcast_type: BroadcastType<B>,
    pub connected_hook: ServerHookHandler,
    pub request_hook: ServerHookHandler,
    pub sended_hook: ServerHookHandler,
    pub closed_hook: ServerHookHandler,
}
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 implement BroadcastTypeTrait.

Fields§

§stream: &'a mut Stream

The underlying stream for this WebSocket connection.

§context: &'a mut Context

The Hyperlane context.

This context is associated with this WebSocket connection.

§capacity: Capacity

The capacity.

This is the capacity of the broadcast sender channel.

§broadcast_type: BroadcastType<B>

The broadcast type.

This defines the type of broadcast this WebSocket connection will participate in (point-to-point or point-to-group).

§connected_hook: ServerHookHandler

The connected hook handler.

This hook is executed when the WebSocket connection is established.

§request_hook: ServerHookHandler

The request hook handler.

This hook is executed when a new request is received on the WebSocket.

§sended_hook: ServerHookHandler

The sended hook handler.

This hook is executed after a message has been successfully sent over the WebSocket.

§closed_hook: ServerHookHandler

The closed hook handler.

This hook is executed when the WebSocket connection is closed.

Implementations§

Source§

impl<'a, B> WebSocketConfig<'a, B>

Source

pub fn new(stream: &'a mut Stream, context: &'a mut Context) -> Self

Creates a new WebSocket configuration with the given context.

§Arguments
  • &'a mut Stream - The stream object serving this WebSocket.
  • &'a mut Context - The context object to associate with the WebSocket.
§Returns
  • WebSocketConfig<B> - A new WebSocket configuration instance.
Source§

impl<'a, B> WebSocketConfig<'a, B>

Source

pub fn set_capacity(self, capacity: Capacity) -> Self

Sets the capacity for the broadcast sender.

§Arguments
  • Capacity - The desired capacity.
§Returns
  • WebSocketConfig<B> - The modified WebSocket configuration instance.
Source

pub fn set_context(self, context: &'a mut Context) -> Self

Sets the context for the WebSocket connection.

§Arguments
  • &'a mut Context - The context object to associate with the WebSocket.
§Returns
  • WebSocketConfig<B> - The modified WebSocket configuration instance.
Source

pub fn set_broadcast_type(self, broadcast_type: BroadcastType<B>) -> Self

Sets the broadcast type for the WebSocket connection.

§Arguments
  • BroadcastType<B> - The broadcast type to use for this WebSocket.
§Returns
  • WebSocketConfig<B> - The modified WebSocket configuration instance.
Source

pub fn set_connected_hook<S>(self) -> Self
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 implement ServerHook.
§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>();
Source

pub fn set_request_hook<S>(self) -> Self
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 implement ServerHook.
§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>();
Source

pub fn set_sended_hook<S>(self) -> Self
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 implement ServerHook.
§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>();
Source

pub fn set_closed_hook<S>(self) -> Self
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 implement ServerHook.
§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>();
Source§

impl<'a, B: BroadcastTypeTrait> WebSocketConfig<'a, B>

Source

pub fn get_stream(&self) -> &&'a mut Stream

Source

pub fn get_mut_stream(&mut self) -> &mut &'a mut Stream

Source

pub fn get_context(&self) -> &&'a mut Context

Source

pub fn get_mut_context(&mut self) -> &mut &'a mut Context

Source

pub fn get_capacity(&self) -> Capacity

Source

pub fn get_mut_capacity(&mut self) -> &mut Capacity

Source

pub fn get_broadcast_type(&self) -> &BroadcastType<B>

Source

pub fn get_mut_broadcast_type(&mut self) -> &mut BroadcastType<B>

Source

pub fn get_connected_hook(&self) -> &ServerHookHandler

Source

pub fn get_mut_connected_hook(&mut self) -> &mut ServerHookHandler

Source

pub fn get_request_hook(&self) -> &ServerHookHandler

Source

pub fn get_mut_request_hook(&mut self) -> &mut ServerHookHandler

Source

pub fn get_sended_hook(&self) -> &ServerHookHandler

Source

pub fn get_mut_sended_hook(&mut self) -> &mut ServerHookHandler

Source

pub fn get_closed_hook(&self) -> &ServerHookHandler

Source

pub fn get_mut_closed_hook(&mut self) -> &mut ServerHookHandler

Auto Trait Implementations§

§

impl<'a, B> !RefUnwindSafe for WebSocketConfig<'a, B>

§

impl<'a, B> !UnwindSafe for WebSocketConfig<'a, B>

§

impl<'a, B> Freeze for WebSocketConfig<'a, B>

§

impl<'a, B> Send for WebSocketConfig<'a, B>
where BroadcastType<B>: Send,

§

impl<'a, B> Sync for WebSocketConfig<'a, B>
where BroadcastType<B>: Sync,

§

impl<'a, B> Unpin for WebSocketConfig<'a, B>
where BroadcastType<B>: Unpin,

§

impl<'a, B> UnsafeUnpin for WebSocketConfig<'a, B>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnySend for T
where T: Any + Send,

Source§

impl<T> AnySendSync for T
where T: Any + Send + Sync,

Source§

impl<T> AnySync for T
where T: Any + Sync,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more