Struct tokio_websockets::proto::Message
source · pub struct Message { /* private fields */ }
Expand description
A WebSocket message. This is cheaply clonable and uses Payload
as the
payload storage underneath.
Received messages are always validated prior to dealing with them, so all the type casting methods are either almost or fully zero cost.
Implementations§
source§impl Message
impl Message
sourcepub fn text<P: Into<Payload>>(payload: P) -> Self
pub fn text<P: Into<Payload>>(payload: P) -> Self
Create a new text message. The payload contents must be valid UTF-8.
sourcepub fn close(code: Option<CloseCode>, reason: &str) -> Self
pub fn close(code: Option<CloseCode>, reason: &str) -> Self
Create a new close message. If an non-empty reason is specified, a
CloseCode
must be specified for it to be included.
sourcepub fn into_payload(self) -> Payload
pub fn into_payload(self) -> Payload
Returns the message payload and consumes the message, regardless of type.
sourcepub fn as_payload(&self) -> &Payload
pub fn as_payload(&self) -> &Payload
Returns a reference to the message payload, regardless of message type.
Trait Implementations§
source§impl<T> Sink<Message> for WebSocketStream<T>
impl<T> Sink<Message> for WebSocketStream<T>
source§fn poll_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>
fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>
Attempts to prepare the
Sink
to receive a value. Read moresource§fn start_send(self: Pin<&mut Self>, item: Message) -> Result<(), Self::Error>
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 moreAuto Trait Implementations§
impl !Freeze for Message
impl !RefUnwindSafe for Message
impl Send for Message
impl !Sync for Message
impl Unpin for Message
impl UnwindSafe for Message
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)