pub struct Websocket<In = String, Out = String, E = JsonEncoding> { /* private fields */ }Expand description
A WebSocket connection that can send and receive messages of type In and Out.
Implementations§
Source§impl<I, O, E> Websocket<I, O, E>
impl<I, O, E> Websocket<I, O, E>
pub async fn recv(&self) -> Result<O, WebsocketError>where
O: DeserializeOwned,
E: Encoding,
Sourcepub async fn send(&self, msg: I) -> Result<(), WebsocketError>
pub async fn send(&self, msg: I) -> Result<(), WebsocketError>
Send a typed message over the WebSocket connection.
This method serializes the message using the specified encoding E before sending it.
The message will always be sent as a binary message, even if the encoding is valid UTF-8
like JSON.
Sourcepub async fn send_raw(&self, message: Message) -> Result<(), WebsocketError>
pub async fn send_raw(&self, message: Message) -> Result<(), WebsocketError>
Send a raw message over the WebSocket connection.
This method allows sending text, binary, ping, pong, and close messages directly.
Sourcepub async fn recv_raw(&self) -> Result<Message, WebsocketError>
pub async fn recv_raw(&self) -> Result<Message, WebsocketError>
Receive a raw message from the WebSocket connection.
pub fn protocol(&self) -> Option<&str>
Trait Implementations§
Source§impl<In, Out, E> IntoResponse for Websocket<In, Out, E>
impl<In, Out, E> IntoResponse for Websocket<In, Out, E>
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Create a response.
Auto Trait Implementations§
impl<In = String, Out = String, E = JsonEncoding> !Freeze for Websocket<In, Out, E>
impl<In = String, Out = String, E = JsonEncoding> !RefUnwindSafe for Websocket<In, Out, E>
impl<In, Out, E> Send for Websocket<In, Out, E>
impl<In = String, Out = String, E = JsonEncoding> !Sync for Websocket<In, Out, E>
impl<In, Out, E> Unpin for Websocket<In, Out, E>
impl<In = String, Out = String, E = JsonEncoding> !UnwindSafe for Websocket<In, Out, E>
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
Mutably borrows from an owned value. Read more
Source§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Create an instance of this type from an initialization function
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> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<Ret> SpawnIfAsync<(), Ret> for Ret
impl<Ret> SpawnIfAsync<(), Ret> for Ret
Source§impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
Source§fn super_from(input: T) -> O
fn super_from(input: T) -> O
Convert from a type to another type.
Source§impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
Source§fn super_into(self) -> O
fn super_into(self) -> O
Convert from a type to another type.