Enum Message

pub enum Message

A WebSocket message.

Variants

Text(Utf8Bytes)

A text WebSocket message

Binary(Bytes)

A binary WebSocket message

Ping(Bytes)

A ping message with the specified payload

The payload here must have a length less than 125 bytes.

Ping messages will be automatically responded to by the server, so you do not have to worry about dealing with them yourself.

Pong(Bytes)

A pong message with the specified payload

The payload here must have a length less than 125 bytes.

Pong messages will be automatically sent to the client if a ping message is received, so you do not have to worry about constructing them yourself unless you want to implement a unidirectional heartbeat.

Close(Option<CloseFrame>)

A close message with the optional close frame.

You may "uncleanly" close a WebSocket connection at any time by simply dropping the WebSocket. However, you may also use the graceful closing protocol, in which

  1. peer A sends a close frame, and does not send any further messages;
  2. peer B responds with a close frame, and does not send any further messages;
  3. peer A processes the remaining messages sent by peer B, before finally
  4. both peers close the connection.

After sending a close frame, you may still read messages, but attempts to send another message will error. After receiving a close frame, axum will automatically respond with a close frame if necessary (you do not have to deal with this yourself). Since no further messages will be received, you may either do nothing or explicitly drop the connection.

Implementations

impl Message

fn into_data(self) -> Bytes

Consume the WebSocket and return it as binary data.

fn into_text(self) -> Result<Utf8Bytes, Error>

Attempt to consume the WebSocket message and convert it to a Utf8Bytes.

fn to_text(&self) -> Result<&str, Error>

Attempt to get a &str from the WebSocket message, this will try to convert binary data to utf8.

fn text<S>(string: S) -> Message
where
    S: Into<Utf8Bytes>,

Create a new text WebSocket message from a stringable.

fn binary<B>(bin: B) -> Message
where
    B: Into<Bytes>,

Create a new binary WebSocket message by converting to Bytes.

Trait Implementations

impl Clone for Message

fn clone(&self) -> Message

impl Debug for Message

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

impl Eq for Message

impl From<Bytes> for Message

fn from(data: Bytes) -> Self

impl From<String> for Message

fn from(string: String) -> Self

impl From<Vec<u8>> for Message

fn from(data: Vec<u8>) -> Self

impl PartialEq for Message

fn eq(&self, other: &Message) -> bool

impl StructuralPartialEq for Message

impl<'b> From<&'b [u8]> for Message

fn from(data: &'b [u8]) -> Self

impl<'s> From<&'s str> for Message

fn from(string: &'s str) -> Self

Auto Trait Implementations

impl !Freeze for Message

impl RefUnwindSafe for Message

impl Send for Message

impl Sync for Message

impl Unpin for Message

impl UnsafeUnpin for Message

impl UnwindSafe for Message

Blanket Implementations

impl<Q, K> Equivalent<K> for Message where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

fn equivalent(&self, key: &K) -> bool

impl<Q, K> Equivalent<K> for Message where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

fn equivalent(&self, key: &K) -> bool

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for Message where ST: ?Sized, DT: ?Sized,

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for Message where ST: ?Sized, DT: ?Sized,

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

impl<T> CloneToUninit for Message where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for Message

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> FromRef<T> for Message where T: Clone,

fn from_ref(input: &T) -> T

impl<T> Instrument for Message

impl<T> Read<Exclusive, BecauseExclusive> for Message where T: ?Sized,

impl<T> Same for Message

type Output = T;

impl<T> ToOwned for Message where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T> WithSubscriber for Message

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

fn into(self) -> U

Calls U::from(self).

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

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

type Error = never;
fn try_from(value: U) -> Result<T, never>

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

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

impl<V, T> VZip<V> for Message where V: MultiLane<T>,

fn vzip(self) -> V