Struct websocket_lite::Message
source · [−]pub struct Message { /* private fields */ }
Expand description
A text string, a block of binary data or a WebSocket control frame.
Implementations
sourceimpl Message
impl Message
sourcepub fn new<B>(opcode: Opcode, data: B) -> Result<Message, Utf8Error> where
B: Into<Bytes>,
pub fn new<B>(opcode: Opcode, data: B) -> Result<Message, Utf8Error> where
B: Into<Bytes>,
Creates a message from a Bytes
object.
The message can be tagged as text or binary. When the opcode
parameter is Opcode::Text
this function validates the bytes in data
and returns Err
if they do not contain valid UTF-8 text.
sourcepub fn text<S>(data: S) -> Message where
S: Into<String>,
pub fn text<S>(data: S) -> Message where
S: Into<String>,
Creates a text message from a String
.
sourcepub fn binary<B>(data: B) -> Message where
B: Into<Bytes>,
pub fn binary<B>(data: B) -> Message where
B: Into<Bytes>,
Creates a binary message from any type that can be converted to Bytes
, such as &[u8]
or Vec<u8>
.
sourcepub fn close(reason: Option<(u16, String)>) -> Message
pub fn close(reason: Option<(u16, String)>) -> Message
Creates a message that indicates the connection is about to be closed.
The reason
parameter is an optional numerical status code and text description. Valid reasons
may be defined by a particular WebSocket server.
sourcepub fn ping<B>(data: B) -> Message where
B: Into<Bytes>,
pub fn ping<B>(data: B) -> Message where
B: Into<Bytes>,
Creates a message requesting a pong response.
The client can send one of these to request a pong response from the server.
sourcepub fn pong<B>(data: B) -> Message where
B: Into<Bytes>,
pub fn pong<B>(data: B) -> Message where
B: Into<Bytes>,
Creates a response to a ping message.
The client can send one of these in response to a ping from the server.
sourcepub fn as_text(&self) -> Option<&str>
pub fn as_text(&self) -> Option<&str>
For messages with opcode Opcode::Text
, returns a reference to the text.
Returns None
otherwise.
Trait Implementations
sourceimpl<'a> Encoder<&'a Message> for MessageCodec
impl<'a> Encoder<&'a Message> for MessageCodec
sourceimpl Encoder<Message> for MessageCodec
impl Encoder<Message> for MessageCodec
impl StructuralPartialEq for Message
Auto Trait Implementations
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnwindSafe for Message
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more