pub enum Message {
Text(String),
Binary(Vec<u8>),
Ping(Vec<u8>),
Pong(Vec<u8>),
Close(Option<CloseFrame>),
}Expand description
WebSocket message type
Variants§
Text(String)
Text message (UTF-8 encoded)
Binary(Vec<u8>)
Binary message
Ping(Vec<u8>)
Ping message
Pong(Vec<u8>)
Pong message
Close(Option<CloseFrame>)
Close message
Implementations§
Source§impl Message
impl Message
Sourcepub fn close_with(code: CloseCode, reason: impl Into<String>) -> Self
pub fn close_with(code: CloseCode, reason: impl Into<String>) -> Self
Create a close message with a frame
Sourcepub fn json<T: Serialize>(value: &T) -> Result<Self, WebSocketError>
pub fn json<T: Serialize>(value: &T) -> Result<Self, WebSocketError>
Create a JSON text message from a serializable type
Sourcepub fn as_json<T: DeserializeOwned>(&self) -> Result<T, WebSocketError>
pub fn as_json<T: DeserializeOwned>(&self) -> Result<T, WebSocketError>
Try to deserialize a text message as JSON
Sourcepub fn into_bytes(self) -> Option<Vec<u8>>
pub fn into_bytes(self) -> Option<Vec<u8>>
Convert to bytes, consuming the message
Trait Implementations§
impl Eq for Message
impl StructuralPartialEq for Message
Auto 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§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more