Struct websocket_codec::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: Into<Bytes>>(opcode: Opcode, data: B) -> Result<Self, Utf8Error>
pub fn new<B: Into<Bytes>>(opcode: Opcode, data: B) -> Result<Self, Utf8Error>
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 binary<B: Into<Bytes>>(data: B) -> Self
pub fn binary<B: Into<Bytes>>(data: B) -> Self
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)>) -> Self
pub fn close(reason: Option<(u16, String)>) -> Self
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: Into<Bytes>>(data: B) -> Self
pub fn ping<B: Into<Bytes>>(data: B) -> Self
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: Into<Bytes>>(data: B) -> Self
pub fn pong<B: Into<Bytes>>(data: B) -> Self
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>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more
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