pub trait PacketKind {
Show 17 associated constants and 0 method
const IS_CONNECT: bool = false;
const IS_CONNACK: bool = false;
const IS_PUBLISH: bool = false;
const IS_PUBACK: bool = false;
const IS_PUBREC: bool = false;
const IS_PUBREL: bool = false;
const IS_PUBCOMP: bool = false;
const IS_SUBSCRIBE: bool = false;
const IS_SUBACK: bool = false;
const IS_UNSUBSCRIBE: bool = false;
const IS_UNSUBACK: bool = false;
const IS_PINGREQ: bool = false;
const IS_PINGRESP: bool = false;
const IS_DISCONNECT: bool = false;
const IS_AUTH: bool = false;
const IS_V3_1_1: bool = false;
const IS_V5_0: bool = false;
}
Expand description
MIT License
Copyright (c) 2025 Takatoshi Kondo
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Trait for compile-time packet classification and type introspection
PacketKind
provides a way to classify MQTT packet types at compile time using
constant boolean flags. This enables efficient type-based dispatch and filtering
without runtime overhead. Each MQTT packet type implements this trait with
appropriate flags set to true
.
The trait includes flags for:
- Packet types: CONNECT, CONNACK, PUBLISH, PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK, PINGREQ, PINGRESP, DISCONNECT, AUTH
- Protocol versions: V3_1_1, V5_0
§Examples
use mqtt_protocol_core::mqtt::packet::PacketKind;
use mqtt_protocol_core::mqtt::packet::v5_0::Connect;
// Check packet type at compile time
if Connect::IS_CONNECT {
println!("This is a CONNECT packet");
}
// Check protocol version
if Connect::IS_V5_0 {
println!("This is a v5.0 packet");
}
Provided Associated Constants§
Sourceconst IS_CONNECT: bool = false
const IS_CONNECT: bool = false
true
if this is a CONNECT packet
Sourceconst IS_CONNACK: bool = false
const IS_CONNACK: bool = false
true
if this is a CONNACK packet
Sourceconst IS_PUBLISH: bool = false
const IS_PUBLISH: bool = false
true
if this is a PUBLISH packet
Sourceconst IS_PUBCOMP: bool = false
const IS_PUBCOMP: bool = false
true
if this is a PUBCOMP packet
Sourceconst IS_SUBSCRIBE: bool = false
const IS_SUBSCRIBE: bool = false
true
if this is a SUBSCRIBE packet
Sourceconst IS_UNSUBSCRIBE: bool = false
const IS_UNSUBSCRIBE: bool = false
true
if this is an UNSUBSCRIBE packet
Sourceconst IS_UNSUBACK: bool = false
const IS_UNSUBACK: bool = false
true
if this is an UNSUBACK packet
Sourceconst IS_PINGREQ: bool = false
const IS_PINGREQ: bool = false
true
if this is a PINGREQ packet
Sourceconst IS_PINGRESP: bool = false
const IS_PINGRESP: bool = false
true
if this is a PINGRESP packet
Sourceconst IS_DISCONNECT: bool = false
const IS_DISCONNECT: bool = false
true
if this is a DISCONNECT packet
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<T: PacketKind> PacketKind for &T
PacketKind
implementation for references to packet types
impl<T: PacketKind> PacketKind for &T
PacketKind
implementation for references to packet types
This implementation forwards all flags from the referenced type, allowing packet references to be used with the same type checking.
const IS_CONNECT: bool = T::IS_CONNECT
const IS_CONNACK: bool = T::IS_CONNACK
const IS_PUBLISH: bool = T::IS_PUBLISH
const IS_PUBACK: bool = T::IS_PUBACK
const IS_PUBREC: bool = T::IS_PUBREC
const IS_PUBREL: bool = T::IS_PUBREL
const IS_PUBCOMP: bool = T::IS_PUBCOMP
const IS_SUBSCRIBE: bool = T::IS_SUBSCRIBE
const IS_SUBACK: bool = T::IS_SUBACK
const IS_UNSUBSCRIBE: bool = T::IS_UNSUBSCRIBE
const IS_UNSUBACK: bool = T::IS_UNSUBACK
const IS_PINGREQ: bool = T::IS_PINGREQ
const IS_PINGRESP: bool = T::IS_PINGRESP
const IS_DISCONNECT: bool = T::IS_DISCONNECT
const IS_AUTH: bool = T::IS_AUTH
const IS_V3_1_1: bool = T::IS_V3_1_1
const IS_V5_0: bool = T::IS_V5_0
Implementors§
Source§impl PacketKind for mqtt_protocol_core::mqtt::packet::v3_1_1::Connack
PacketKind
implementation for v3.1.1 CONNACK packet
impl PacketKind for mqtt_protocol_core::mqtt::packet::v3_1_1::Connack
PacketKind
implementation for v3.1.1 CONNACK packet
Source§impl PacketKind for mqtt_protocol_core::mqtt::packet::v3_1_1::Connect
PacketKind
implementation for v3.1.1 CONNECT packet
impl PacketKind for mqtt_protocol_core::mqtt::packet::v3_1_1::Connect
PacketKind
implementation for v3.1.1 CONNECT packet
Source§impl PacketKind for mqtt_protocol_core::mqtt::packet::v3_1_1::Disconnect
PacketKind
implementation for v3.1.1 DISCONNECT packet
impl PacketKind for mqtt_protocol_core::mqtt::packet::v3_1_1::Disconnect
PacketKind
implementation for v3.1.1 DISCONNECT packet
Source§impl PacketKind for mqtt_protocol_core::mqtt::packet::v3_1_1::Pingreq
PacketKind
implementation for v3.1.1 PINGREQ packet
impl PacketKind for mqtt_protocol_core::mqtt::packet::v3_1_1::Pingreq
PacketKind
implementation for v3.1.1 PINGREQ packet
Source§impl PacketKind for mqtt_protocol_core::mqtt::packet::v3_1_1::Pingresp
PacketKind
implementation for v3.1.1 PINGRESP packet
impl PacketKind for mqtt_protocol_core::mqtt::packet::v3_1_1::Pingresp
PacketKind
implementation for v3.1.1 PINGRESP packet
Source§impl PacketKind for Auth
PacketKind
implementation for v5.0 AUTH packet (v5.0 exclusive)
impl PacketKind for Auth
PacketKind
implementation for v5.0 AUTH packet (v5.0 exclusive)
Source§impl PacketKind for mqtt_protocol_core::mqtt::packet::v5_0::Connack
PacketKind
implementation for v5.0 CONNACK packet
impl PacketKind for mqtt_protocol_core::mqtt::packet::v5_0::Connack
PacketKind
implementation for v5.0 CONNACK packet
Source§impl PacketKind for mqtt_protocol_core::mqtt::packet::v5_0::Connect
PacketKind
implementation for v5.0 CONNECT packet
impl PacketKind for mqtt_protocol_core::mqtt::packet::v5_0::Connect
PacketKind
implementation for v5.0 CONNECT packet
Source§impl PacketKind for mqtt_protocol_core::mqtt::packet::v5_0::Disconnect
impl PacketKind for mqtt_protocol_core::mqtt::packet::v5_0::Disconnect
Source§impl PacketKind for mqtt_protocol_core::mqtt::packet::v5_0::Pingreq
PacketKind
implementation for v5.0 PINGREQ packet
impl PacketKind for mqtt_protocol_core::mqtt::packet::v5_0::Pingreq
PacketKind
implementation for v5.0 PINGREQ packet
Source§impl PacketKind for mqtt_protocol_core::mqtt::packet::v5_0::Pingresp
impl PacketKind for mqtt_protocol_core::mqtt::packet::v5_0::Pingresp
impl<PacketIdType> PacketKind for GenericPacket<PacketIdType>where
PacketIdType: IsPacketId + Serialize,
PacketKind
implementation for GenericPacket
enum
For enum types, all flags are false
at compile time since the actual
packet type is determined at runtime. This implementation provides a
fallback for generic packet handling where compile-time type information
is not available.
Source§impl<PacketIdType> PacketKind for mqtt_protocol_core::mqtt::packet::v3_1_1::GenericPuback<PacketIdType>where
PacketIdType: IsPacketId,
impl<PacketIdType> PacketKind for mqtt_protocol_core::mqtt::packet::v3_1_1::GenericPuback<PacketIdType>where
PacketIdType: IsPacketId,
Source§impl<PacketIdType> PacketKind for mqtt_protocol_core::mqtt::packet::v3_1_1::GenericPubcomp<PacketIdType>where
PacketIdType: IsPacketId,
impl<PacketIdType> PacketKind for mqtt_protocol_core::mqtt::packet::v3_1_1::GenericPubcomp<PacketIdType>where
PacketIdType: IsPacketId,
Source§impl<PacketIdType> PacketKind for mqtt_protocol_core::mqtt::packet::v3_1_1::GenericPublish<PacketIdType>where
PacketIdType: IsPacketId + 'static,
PacketKind
implementation for generic v3.1.1 PUBLISH packet
impl<PacketIdType> PacketKind for mqtt_protocol_core::mqtt::packet::v3_1_1::GenericPublish<PacketIdType>where
PacketIdType: IsPacketId + 'static,
PacketKind
implementation for generic v3.1.1 PUBLISH packet