Struct warp::filters::ws::Message

source ·
pub struct Message { /* private fields */ }
Expand description

A WebSocket message.

This will likely become a non-exhaustive enum in the future, once that language feature has stabilized.

Implementations§

source§

impl Message

source

pub fn text<S: Into<String>>(s: S) -> Message

Construct a new Text Message.

source

pub fn binary<V: Into<Vec<u8>>>(v: V) -> Message

Construct a new Binary Message.

source

pub fn ping<V: Into<Vec<u8>>>(v: V) -> Message

Construct a new Ping Message.

source

pub fn pong<V: Into<Vec<u8>>>(v: V) -> Message

Construct a new Pong Message.

Note that one rarely needs to manually construct a Pong message because the underlying tungstenite socket automatically responds to the Ping messages it receives. Manual construction might still be useful in some cases like in tests or to send unidirectional heartbeats.

source

pub fn close() -> Message

Construct the default Close Message.

source

pub fn close_with( code: impl Into<u16>, reason: impl Into<Cow<'static, str>> ) -> Message

Construct a Close Message with a code and reason.

source

pub fn is_text(&self) -> bool

Returns true if this message is a Text message.

source

pub fn is_binary(&self) -> bool

Returns true if this message is a Binary message.

source

pub fn is_close(&self) -> bool

Returns true if this message a is a Close message.

source

pub fn is_ping(&self) -> bool

Returns true if this message is a Ping message.

source

pub fn is_pong(&self) -> bool

Returns true if this message is a Pong message.

source

pub fn close_frame(&self) -> Option<(u16, &str)>

Try to get the close frame (close code and reason)

source

pub fn to_str(&self) -> Result<&str, ()>

Try to get a reference to the string text, if this is a Text message.

source

pub fn as_bytes(&self) -> &[u8]

Return the bytes of this message, if the message can contain data.

source

pub fn into_bytes(self) -> Vec<u8>

Destructure this message into binary data.

Trait Implementations§

source§

impl Clone for Message

source§

fn clone(&self) -> Message

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Message

source§

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

Formats the value using the given formatter. Read more
source§

impl From<Message> for Vec<u8>

source§

fn from(m: Message) -> Self

Converts to this type from the input type.
source§

impl PartialEq<Message> for Message

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Sink<Message> for WebSocket

§

type Error = Error

The type of value produced by the sink when an error occurs.
source§

fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Attempts to prepare the Sink to receive a value. Read more
source§

fn start_send(self: Pin<&mut Self>, item: Message) -> Result<(), Self::Error>

Begin the process of sending a value to the sink. Each call to this function must be preceded by a successful call to poll_ready which returned Poll::Ready(Ok(())). Read more
source§

fn poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Flush any remaining output from this sink. Read more
source§

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Flush any remaining output and close this sink, if necessary. Read more
source§

impl Sink<Message> for WsClient

§

type Error = WsError

The type of value produced by the sink when an error occurs.
source§

fn poll_ready( self: Pin<&mut Self>, context: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Attempts to prepare the Sink to receive a value. Read more
source§

fn start_send(self: Pin<&mut Self>, message: Message) -> Result<(), Self::Error>

Begin the process of sending a value to the sink. Each call to this function must be preceded by a successful call to poll_ready which returned Poll::Ready(Ok(())). Read more
source§

fn poll_flush( self: Pin<&mut Self>, context: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Flush any remaining output from this sink. Read more
source§

fn poll_close( self: Pin<&mut Self>, context: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Flush any remaining output and close this sink, if necessary. Read more
source§

impl Eq for Message

source§

impl StructuralEq for Message

source§

impl StructuralPartialEq for Message

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

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

source§

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

Compare self to key and return true if they are equal.
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 Twhere 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<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

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