WebSocket

Struct WebSocket 

Source
pub struct WebSocket<'buf, RW, Rng> { /* private fields */ }
Expand description

A WebSocket connection.

§Defaults:

  • auto_pong: true
  • auto_close: true

Implementations§

Source§

impl<'buf, RW, Rng> WebSocket<'buf, RW, Rng>

Source

pub const fn client( inner: RW, rng: Rng, read_buffer: &'buf mut [u8], write_buffer: &'buf mut [u8], fragments_buffer: &'buf mut [u8], ) -> Self

Creates a new WebSocket client after a successful handshake.

Source

pub const fn server( inner: RW, rng: Rng, read_buffer: &'buf mut [u8], write_buffer: &'buf mut [u8], fragments_buffer: &'buf mut [u8], ) -> Self

Creates a new WebSocket server after a successful handshake.

Source

pub async fn connect<const N: usize>( options: ConnectOptions<'_, '_>, inner: RW, rng: Rng, read_buffer: &'buf mut [u8], write_buffer: &'buf mut [u8], fragments_buffer: &'buf mut [u8], ) -> Result<Self, Error<RW::Error>>
where RW: Read + Write, Rng: RngCore,

Creates a new WebSocket client and performs the handshake.

§Generic Parameters

N: The maximum number of headers to accept in the handshake response.

Source

pub async fn connect_with<const N: usize, F, T, E>( options: ConnectOptions<'_, '_>, inner: RW, rng: Rng, read_buffer: &'buf mut [u8], write_buffer: &'buf mut [u8], fragments_buffer: &'buf mut [u8], on_response: F, ) -> Result<(Self, T), Error<RW::Error, E>>
where F: for<'a> Fn(&Response<'a, N>) -> Result<T, E>, RW: Read + Write, Rng: RngCore,

Creates a new WebSocket client and performs the handshake with a custom response handler.

§Generic Parameters

N: The maximum number of headers to accept in the handshake response.

Source

pub async fn accept<const N: usize>( options: AcceptOptions<'_, '_>, inner: RW, rng: Rng, read_buffer: &'buf mut [u8], write_buffer: &'buf mut [u8], fragments_buffer: &'buf mut [u8], ) -> Result<Self, Error<RW::Error>>
where RW: Read + Write,

Creates a new WebSocket server and performs the handshake.

§Generic Parameters

N: The maximum number of headers to accept in the handshake request.

Source

pub async fn accept_with<const N: usize, F, T, E>( options: AcceptOptions<'_, '_>, inner: RW, rng: Rng, read_buffer: &'buf mut [u8], write_buffer: &'buf mut [u8], fragments_buffer: &'buf mut [u8], on_request: F, ) -> Result<(Self, T), Error<RW::Error, E>>
where F: for<'a> Fn(&Request<'a, N>) -> Result<T, E>, RW: Read + Write,

Creates a new WebSocket server and performs the handshake with a custom request handler.

§Generic Parameters

N: The maximum number of headers to accept in the handshake request.

Source

pub const fn with_auto_pong(self, auto_pong: bool) -> Self

Sets whether to automatically send a Pong response.

Source

pub const fn with_auto_close(self, auto_close: bool) -> Self

Sets whether to automatically close the connection on receiving a Close frame.

Source

pub const fn inner(&self) -> &RW

Returns reference to the reader/writer.

Source

pub const fn inner_mut(&mut self) -> &mut RW

Returns mutable reference to the reader/writer.

Source

pub fn into_inner(self) -> RW

Consumes the WebSocket and returns the reader/writer.

Source

pub const fn framable(&self) -> usize

Returns the number of bytes that can be framed.

Source

pub async fn send( &mut self, message: Message<'_>, ) -> Result<(), Error<RW::Error>>
where RW: Write, Rng: RngCore,

Sends a WebSocket message.

Source

pub async fn send_fragmented( &mut self, message: Message<'_>, fragment_size: usize, ) -> Result<(), Error<RW::Error>>
where RW: Write, Rng: RngCore,

Sends a fragmented WebSocket message.

Source

pub fn split_with<F, R, W>( self, split: F, ) -> (WebSocketRead<'buf, R>, WebSocketWrite<'buf, W, Rng>)
where F: FnOnce(RW) -> (R, W),

Splits the WebSocket into a WebSocketRead and a WebSocketWrite with the provided split function.

§Note

auto_pong and auto_close will NOT be applied to the split instances.

Trait Implementations§

Source§

impl<'buf, RW: Debug, Rng: Debug> Debug for WebSocket<'buf, RW, Rng>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'buf, RW, Rng> Freeze for WebSocket<'buf, RW, Rng>
where RW: Freeze, Rng: Freeze,

§

impl<'buf, RW, Rng> RefUnwindSafe for WebSocket<'buf, RW, Rng>
where RW: RefUnwindSafe, Rng: RefUnwindSafe,

§

impl<'buf, RW, Rng> Send for WebSocket<'buf, RW, Rng>
where RW: Send, Rng: Send,

§

impl<'buf, RW, Rng> Sync for WebSocket<'buf, RW, Rng>
where RW: Sync, Rng: Sync,

§

impl<'buf, RW, Rng> Unpin for WebSocket<'buf, RW, Rng>
where RW: Unpin, Rng: Unpin,

§

impl<'buf, RW, Rng> !UnwindSafe for WebSocket<'buf, RW, Rng>

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> 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, 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.