Skip to main content

Payload

Struct Payload 

#[repr(transparent)]
pub struct Payload([u8]);
Expand description

An application message payload.

The length is at most Payload::MAX_LEN, the largest Remaining Length of any packet. Because the topic and properties also count toward that limit, a payload close to it can still be too large to send. This is an unsized type like [[u8]].

Tuple Fields§

§0: [u8]

Implementations§

§

impl Payload

pub const MAX_LEN: usize = Vbi::MAX_USIZE

The maximum payload length in bytes.

pub const fn new(bytes: &[u8]) -> Result<&Self, PayloadTooLarge>

Wraps bytes.

§Errors

Returns PayloadTooLarge if bytes exceed MAX_LEN.

pub(super) const fn from_validated(bytes: &[u8]) -> &Self

Wraps bytes, which the caller has already checked against MAX_LEN.

pub const fn as_slice(&self) -> &[u8] ⓘ

Returns the payload bytes.

pub const fn len(&self) -> usize

Returns the length in bytes.

pub const fn is_empty(&self) -> bool

Returns true if the payload is empty.

pub const fn len_u32(&self) -> u32

Returns the length as a u32.

§

impl Payload

pub fn try_to_owned(&self) -> Result<PayloadBuf, TryReserveError>

Available on crate feature alloc only.

Copies the payload into a PayloadBuf without panicking if the allocation fails.

§Errors

Returns TryReserveError if the allocation fails.

Trait Implementations§

§

impl AsRef<Payload> for PayloadBuf

Available on crate feature alloc only.
§

fn as_ref(&self) -> &Payload

Converts this type into a shared reference of the (usually inferred) input type.
§

impl AsRef<[u8]> for Payload

§

fn as_ref(&self) -> &[u8] ⓘ

Converts this type into a shared reference of the (usually inferred) input type.
§

impl Borrow<Payload> for PayloadBuf

Available on crate feature alloc only.
§

fn borrow(&self) -> &Payload

Immutably borrows from an owned value. Read more
§

impl Debug for Payload

§

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

Formats the value using the given formatter. Read more
§

impl Eq for Payload

§

impl Hash for Payload

§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
§

impl PartialEq for Payload

§

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

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

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

Inequality operator !=. Read more
§

impl<const N: usize> PartialEq<[u8; N]> for Payload

§

fn eq(&self, other: &[u8; N]) -> bool

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

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

Inequality operator !=. Read more
§

impl PartialEq<[u8]> for Payload

§

fn eq(&self, other: &[u8]) -> bool

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

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

Inequality operator !=. Read more
§

impl StructuralPartialEq for Payload

§

impl ToOwned for Payload

Available on crate feature alloc only.
§

type Owned = PayloadBuf

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> PayloadBuf

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

fn clone_into(&self, target: &mut Self::Owned)

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

impl<'a> TryFrom<&'a [u8]> for &'a Payload

§

type Error = PayloadTooLarge

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

fn try_from(bytes: &'a [u8]) -> Result<Self, PayloadTooLarge>

Performs the conversion.

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