Skip to main content

Payload

Enum Payload 

Source
#[non_exhaustive]
pub enum Payload { Binary(Bytes), Text(Vec<Value>), Mixed { args: Vec<Value>, attachments: Vec<Bytes>, }, }
Expand description

The arguments of an event or an ack.

socket.io sends a list of arguments; each is JSON or binary. Received arguments arrive as:

  • Payload::Text: JSON only (the common case),
  • Payload::Binary: exactly one binary argument,
  • Payload::Mixed: binary data anywhere else (several buffers, a buffer next to JSON arguments, a buffer inside an object).

Build one with From (a Value, a Vec<Value>, a string, bytes) or with Payload::serialize for any Serialize type; read one with Payload::arg / Payload::deserialize.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Binary(Bytes)

One binary argument.

§

Text(Vec<Value>)

JSON arguments.

§

Mixed

Arguments with binary data anywhere in them: each {"_placeholder":true,"num":n} in args stands for attachments[n] (socket.io-parser binary encoding). Build placeholders with Payload::placeholder.

Fields

§args: Vec<Value>

The JSON arguments, placeholders included.

§attachments: Vec<Bytes>

The binary attachments the placeholders refer to.

Implementations§

Source§

impl Payload

Source

pub fn placeholder(num: usize) -> Value

The placeholder for attachments[num] in Payload::Mixed.

Source

pub fn empty() -> Self

No arguments (socket.emit("ping")).

Source

pub fn serialize<T: Serialize + ?Sized>(value: &T) -> Result<Self>

One argument from any Serialize value.

Source

pub fn args(&self) -> &[Value]

The JSON arguments (placeholders included for Payload::Mixed; empty for Payload::Binary).

Source

pub fn binary(&self) -> &[Bytes]

The binary data: the one buffer of Payload::Binary, the attachments of Payload::Mixed.

Source

pub fn len(&self) -> usize

Number of arguments.

Source

pub fn is_empty(&self) -> bool

No arguments at all.

Source

pub fn arg<T: DeserializeOwned>(&self, index: usize) -> Result<T>

Argument index as T (null when it is missing, so Option<T> reads optional ones).

Source

pub fn deserialize<T: DeserializeOwned>(&self) -> Result<T>

All arguments as T: a tuple (A, B), a Vec<_>, or a struct with one field per argument position.

Trait Implementations§

Source§

impl Clone for Payload

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Payload

Source§

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

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

impl Default for Payload

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Payload

Source§

impl From<&'static [u8]> for Payload

Source§

fn from(val: &'static [u8]) -> Self

One binary argument.

Source§

impl From<&str> for Payload

Source§

fn from(string: &str) -> Self

One string argument.

Source§

impl From<()> for Payload

Source§

fn from(_: ()) -> Self

No arguments.

Source§

impl From<Bytes> for Payload

Source§

fn from(bytes: Bytes) -> Self

One binary argument.

Source§

impl From<String> for Payload

Source§

fn from(string: String) -> Self

One string argument (never parsed as JSON).

Source§

impl From<Value> for Payload

Source§

fn from(value: Value) -> Self

One argument.

Source§

impl From<Vec<Value>> for Payload

Source§

fn from(values: Vec<Value>) -> Self

One argument per value.

Source§

impl From<Vec<u8>> for Payload

Source§

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

One binary argument.

Source§

impl From<bool> for Payload

Source§

fn from(value: bool) -> Self

One JSON argument.

Source§

impl From<f32> for Payload

Source§

fn from(value: f32) -> Self

One JSON argument.

Source§

impl From<f64> for Payload

Source§

fn from(value: f64) -> Self

One JSON argument.

Source§

impl From<i8> for Payload

Source§

fn from(value: i8) -> Self

One JSON argument.

Source§

impl From<i16> for Payload

Source§

fn from(value: i16) -> Self

One JSON argument.

Source§

impl From<i32> for Payload

Source§

fn from(value: i32) -> Self

One JSON argument.

Source§

impl From<i64> for Payload

Source§

fn from(value: i64) -> Self

One JSON argument.

Source§

impl From<u8> for Payload

Source§

fn from(value: u8) -> Self

One JSON argument.

Source§

impl From<u16> for Payload

Source§

fn from(value: u16) -> Self

One JSON argument.

Source§

impl From<u32> for Payload

Source§

fn from(value: u32) -> Self

One JSON argument.

Source§

impl From<u64> for Payload

Source§

fn from(value: u64) -> Self

One JSON argument.

Source§

impl PartialEq for Payload

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Payload

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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 = !

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

fn try_from(value: U) -> Result<T, !>

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

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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