Skip to main content

Message

Enum Message 

Source
pub enum Message {
    Text(Bytes),
    Binary(Bytes),
    Ping(Bytes),
    Pong(Bytes),
    Close(Option<CloseFrame>),
}
Expand description

A WebSocket message.

Backend-agnostic representation handed to consumers of the nautilus-network transport layer. Each backend provides From impls between its native Message type and this enum.

Text is documented to carry UTF-8 by contract but the type does not enforce it. Backends that already validate (such as tokio-tungstenite) produce valid bytes; an in-house HFT backend may skip validation for performance and rely on the consumer’s parser to catch malformed bytes. Use Self::as_text to view the payload as &str.

Variants§

§

Text(Bytes)

Text message. Payload is UTF-8 by contract, not by type guarantee.

§

Binary(Bytes)

Binary message.

§

Ping(Bytes)

Ping control frame. Payload bounded to 125 bytes by RFC 6455.

§

Pong(Bytes)

Pong control frame. Payload bounded to 125 bytes by RFC 6455.

§

Close(Option<CloseFrame>)

Close control frame with optional close frame payload.

Implementations§

Source§

impl Message

Source

pub fn text(s: impl Into<String>) -> Self

Construct a text message from any string-like value.

Source

pub fn as_text(&self) -> Option<&str>

Borrow a text message as &str if the payload is valid UTF-8.

Validates on each call; for hot paths where the producer is trusted, callers can read the bytes directly via Self::as_bytes and feed them to a parser that catches malformed input.

Source

pub fn binary(data: impl Into<Bytes>) -> Self

Construct a binary message.

Source

pub fn ping(data: impl Into<Bytes>) -> Self

Construct a ping message.

Source

pub fn pong(data: impl Into<Bytes>) -> Self

Construct a pong message.

Source

pub const fn is_text(&self) -> bool

Returns true for text messages.

Source

pub const fn is_binary(&self) -> bool

Returns true for binary messages.

Source

pub const fn is_ping(&self) -> bool

Returns true for ping messages.

Source

pub const fn is_pong(&self) -> bool

Returns true for pong messages.

Source

pub const fn is_close(&self) -> bool

Returns true for close messages.

Source

pub const fn is_control(&self) -> bool

Returns true for control frames (ping, pong, close).

Source

pub fn as_bytes(&self) -> &[u8]

Returns the message payload as a byte slice.

For close frames, returns the reason payload as bytes.

Source

pub fn into_bytes(self) -> Bytes

Consumes the message and returns its payload as Bytes.

For close frames, returns an empty Bytes.

Trait Implementations§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Message

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Message

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&str> for Message

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Bytes> for Message

Source§

fn from(b: Bytes) -> Self

Converts to this type from the input type.
Source§

impl From<Message> for Message

Source§

fn from(value: Message) -> Self

Converts to this type from the input type.
Source§

impl From<Message> for Message

Source§

fn from(value: SockudoMessage) -> Self

Converts to this type from the input type.
Source§

impl From<Message> for Message

Source§

fn from(value: Message) -> Self

Convert a neutral Message into a sockudo [SockudoMessage].

Conversion is infallible: both enums carry payloads as bytes::Bytes across all variants. Sockudo validates UTF-8 on Text frames at parse time, not at send time, so feeding it non-UTF-8 bytes via [Self::Text] is the caller’s responsibility.

Source§

impl From<String> for Message

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Message

Source§

fn from(v: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Message

Source§

fn eq(&self, other: &Message) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S> Sink<Message> for SockudoTransport<S>
where S: AsyncRead + AsyncWrite + Unpin,

Source§

type Error = TransportError

The type of value produced by the sink when an error occurs.
Source§

fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>

Attempts to prepare the Sink to receive a value. Read more
Source§

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 more
Source§

fn poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>

Flush any remaining output from this sink. Read more
Source§

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>

Flush any remaining output and close this sink, if necessary. Read more
Source§

impl<S> Sink<Message> for TungsteniteTransport<S>
where S: AsyncRead + AsyncWrite + Unpin,

Source§

type Error = TransportError

The type of value produced by the sink when an error occurs.
Source§

fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>

Attempts to prepare the Sink to receive a value. Read more
Source§

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 more
Source§

fn poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>

Flush any remaining output from this sink. Read more
Source§

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>

Flush any remaining output and close this sink, if necessary. Read more
Source§

impl TryFrom<Message> for Message

Source§

fn try_from(value: Message) -> Result<Self, Self::Error>

Convert a neutral Message into a tungstenite [tungstenite::Message].

Validates the Text payload as UTF-8 because tungstenite refuses to transmit a Text frame whose body is not valid UTF-8. Other variants are infallible.

§Errors

Returns TransportError::InvalidUtf8 if a Text payload is not valid UTF-8.

Source§

type Error = TransportError

The type returned in the event of a conversion error.
Source§

impl Eq for Message

Source§

impl StructuralPartialEq for Message

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> Ungil for T
where T: Send,