MqttBytes

Struct MqttBytes 

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

A byte slice that satisfies the MQTT v5 Binary Data length limit (at most 65 535 bytes).

This is an unsized type like [[u8]]. Use it for borrowed references and MqttBytesBuf for owned values.

Tuple Fields§

§0: [u8]

Implementations§

§

impl MqttBytes

pub const EMPTY: &'static Self

The empty bytes.

pub const unsafe fn new_unchecked(data: &[u8]) -> &Self

Create binary data without validating the length invariant.

§Safety

The caller must guarantee that data.len() <= 65_535.

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

Validate and wrap a &[u8].

§Errors

Returns DataError::TooLong if data exceeds 65 535 bytes.

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

Returns the raw byte slice.

pub const fn len(&self) -> usize

Returns the length in bytes.

pub const fn len_u16(&self) -> u16

Returns the length as a u16 for encoding.

pub const fn encoded_len(&self) -> usize

Returns the number of bytes needed to encode this value.

pub const fn is_empty(&self) -> bool

Returns true if the byte slice is empty.

Trait Implementations§

§

impl AsRef<[u8]> for MqttBytes

§

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

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

impl AsRef<MqttBytes> for MqttBytesBuf

Available on crate feature alloc only.
§

fn as_ref(&self) -> &MqttBytes

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

impl Borrow<MqttBytes> for MqttBytesBuf

Available on crate feature alloc only.
§

fn borrow(&self) -> &MqttBytes

Immutably borrows from an owned value. Read more
§

impl Debug for MqttBytes

§

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

Formats the value using the given formatter. Read more
§

impl Hash for MqttBytes

§

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

Feeds this value into the given Hasher. Read more
§

impl PartialEq for MqttBytes

§

fn eq(&self, other: &MqttBytes) -> 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.
§

impl ToOwned for MqttBytes

Available on crate feature alloc only.
§

type Owned = MqttBytesBuf

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> Self::Owned

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 MqttBytes

§

type Error = DataError

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

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

Performs the conversion.
§

impl Eq for MqttBytes

§

impl StructuralPartialEq for MqttBytes

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