[−][src]Struct websocket::message::Message
Represents a WebSocket message.
This message also has the ability to not own its payload, and stores its entire payload in
chunks that get written in order when the message gets sent. This makes the write_payload
allocate less memory than the payload
method (which creates a new buffer every time).
Incidentally this (the default implementation of Message
) implements the DataFrame
trait
because this message just gets sent as one single DataFrame
.
Fields
opcode: Type
Type of WebSocket message
cd_status_code: Option<u16>
Optional status code to send when closing a connection. (only used if this message is of Type::Close)
payload: Cow<'a, [u8]>
Main payload
Methods
impl<'a> Message<'a>
[src]
[−]
impl<'a> Message<'a>
pub fn text<S>(data: S) -> Self where
S: Into<Cow<'a, str>>,
[src]
[−]
pub fn text<S>(data: S) -> Self where
S: Into<Cow<'a, str>>,
Create a new WebSocket message with text data
pub fn binary<B>(data: B) -> Self where
B: IntoCowBytes<'a>,
[src]
[−]
pub fn binary<B>(data: B) -> Self where
B: IntoCowBytes<'a>,
Create a new WebSocket message with binary data
pub fn close() -> Self
[src]
[−]
pub fn close() -> Self
Create a new WebSocket message that signals the end of a WebSocket connection, although messages can still be sent after sending this
pub fn close_because<S>(code: u16, reason: S) -> Self where
S: Into<Cow<'a, str>>,
[src]
[−]
pub fn close_because<S>(code: u16, reason: S) -> Self where
S: Into<Cow<'a, str>>,
Create a new WebSocket message that signals the end of a WebSocket connection and provide a text reason and a status code for why. Messages can still be sent after sending this message.
pub fn ping<P>(data: P) -> Self where
P: IntoCowBytes<'a>,
[src]
[−]
pub fn ping<P>(data: P) -> Self where
P: IntoCowBytes<'a>,
Create a ping WebSocket message, a pong is usually sent back after sending this with the same data
pub fn pong<P>(data: P) -> Self where
P: IntoCowBytes<'a>,
[src]
[−]
pub fn pong<P>(data: P) -> Self where
P: IntoCowBytes<'a>,
Create a pong WebSocket message, usually a response to a ping message
pub fn into_pong(&mut self) -> Result<(), ()>
[src]
[−]
pub fn into_pong(&mut self) -> Result<(), ()>
Convert a ping message to a pong, keeping the data. This will fail if the original message is not a ping.
Trait Implementations
impl<'a> DataFrame for Message<'a>
[src]
[+]
impl<'a> DataFrame for Message<'a>
impl<'a> Message for Message<'a>
[src]
[+]
impl<'a> Message for Message<'a>
impl<'a> PartialEq<Message<'a>> for Message<'a>
[src]
[+]
impl<'a> PartialEq<Message<'a>> for Message<'a>
impl<'m> From<Message<'m>> for OwnedMessage
[src]
[+]
impl<'m> From<Message<'m>> for OwnedMessage
impl<'m> From<OwnedMessage> for Message<'m>
[src]
[+]
impl<'m> From<OwnedMessage> for Message<'m>
impl<'a> Clone for Message<'a>
[src]
[+]
impl<'a> Clone for Message<'a>
impl<'a> Eq for Message<'a>
[src]
impl<'a> Eq for Message<'a>
impl<'a> Debug for Message<'a>
[src]
[+]
impl<'a> Debug for Message<'a>
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
[−]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
[−]
impl<T> ToOwned for T where
T: Clone,
type Owned = T
fn to_owned(&self) -> T
[src]
[−]
fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut T)
[src]
[−]
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T> From for T
[src]
[−]
impl<T> From for T
impl<T, U> TryFrom for T where
T: From<U>,
[src]
[−]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
[−]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
[−]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
[−]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
[−]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
[−]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
[−]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
[−]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
[−]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more
impl<T> Typeable for T where
T: Any,
[src]
[−]
impl<T> Typeable for T where
T: Any,
impl<T> Erased for T
[src]
impl<T> Erased for T