Enum Packet

Source
pub enum Packet<'a> {
Show 14 variants Connect(Connect<'a>), Connack(Connack), Publish(Publish<'a>), Puback(Pid), Pubrec(Pid), Pubrel(Pid), Pubcomp(Pid), Subscribe(Subscribe), Suback(Suback), Unsubscribe(Unsubscribe), Unsuback(Pid), Pingreq, Pingresp, Disconnect,
}
Expand description

Base enum for all MQTT packet types.

This is the main type you’ll be interacting with, as an output of decode_slice() and an input of encode(). Most variants can be constructed directly without using methods.

// Simplest form
let pkt = Packet::Connack(Connack { session_present: false,
                                    code: ConnectReturnCode::Accepted });
// Using `Into` trait
let publish = Publish { dup: false,
                        qospid: QosPid::AtMostOnce,
                        retain: false,
                        topic_name: "to/pic",
                        payload: b"payload" };
let pkt: Packet = publish.into();
// Identifyer-only packets
let pkt = Packet::Puback(Pid::try_from(42).unwrap());

Variants§

§

Connect(Connect<'a>)

§

Connack(Connack)

§

Publish(Publish<'a>)

§

Puback(Pid)

§

Pubrec(Pid)

§

Pubrel(Pid)

§

Pubcomp(Pid)

§

Subscribe(Subscribe)

§

Suback(Suback)

§

Unsubscribe(Unsubscribe)

§

Unsuback(Pid)

§

Pingreq

§

Pingresp

§

Disconnect

Implementations§

Source§

impl<'a> Packet<'a>

Source

pub fn get_type(&self) -> PacketType

Return the packet type variant.

This can be used for matching, categorising, debuging, etc. Most users will match directly on Packet instead.

Trait Implementations§

Source§

impl<'a> Clone for Packet<'a>

Source§

fn clone(&self) -> Packet<'a>

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<'a> Debug for Packet<'a>

Source§

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

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

impl<'a> From<Connack> for Packet<'a>

Source§

fn from(p: Connack) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Connect<'a>> for Packet<'a>

Source§

fn from(p: Connect<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Publish<'a>> for Packet<'a>

Source§

fn from(p: Publish<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Suback> for Packet<'a>

Source§

fn from(p: Suback) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Subscribe> for Packet<'a>

Source§

fn from(p: Subscribe) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Unsubscribe> for Packet<'a>

Source§

fn from(p: Unsubscribe) -> Self

Converts to this type from the input type.
Source§

impl<'a> PartialEq for Packet<'a>

Source§

fn eq(&self, other: &Packet<'a>) -> 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<'a> StructuralPartialEq for Packet<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Packet<'a>

§

impl<'a> RefUnwindSafe for Packet<'a>

§

impl<'a> Send for Packet<'a>

§

impl<'a> Sync for Packet<'a>

§

impl<'a> Unpin for Packet<'a>

§

impl<'a> UnwindSafe for Packet<'a>

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, 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> 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.