Skip to content

Commit

Permalink
Merge pull request #237 from matthiasbeyer/add-partialeq
Browse files Browse the repository at this point in the history
Implement PartialEq for all types
  • Loading branch information
TheNeikos authored Mar 21, 2024
2 parents a03e421 + 8ac24b0 commit 0b90438
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 25 deletions.
2 changes: 1 addition & 1 deletion mqtt-format/src/v5/packets/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ crate::v5::properties::define_properties! {
}
}

#[derive(Debug)]
#[derive(Debug, PartialEq)]
#[doc = crate::v5::util::md_speclink!("_Toc3901217")]
pub struct MAuth<'i> {
pub reason: AuthReasonCode,
Expand Down
2 changes: 1 addition & 1 deletion mqtt-format/src/v5/packets/connack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ define_properties![
}
];

#[derive(Debug)]
#[derive(Debug, PartialEq)]
#[doc = crate::v5::util::md_speclink!("_Toc3901074")]
pub struct MConnack<'i> {
pub session_present: bool,
Expand Down
4 changes: 2 additions & 2 deletions mqtt-format/src/v5/packets/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::v5::write::WResult;
use crate::v5::write::WriteMqttPacket;
use crate::v5::MResult;

#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub struct MConnect<'i> {
pub client_identifier: &'i str,
pub username: Option<&'i str>,
Expand Down Expand Up @@ -220,7 +220,7 @@ impl<'i> MConnect<'i> {
}
}

#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub struct Will<'i> {
pub properties: ConnectWillProperties<'i>,
pub topic: &'i str,
Expand Down
2 changes: 1 addition & 1 deletion mqtt-format/src/v5/packets/disconnect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ define_properties! {
}
}

#[derive(Debug)]
#[derive(Debug, PartialEq)]
#[doc = crate::v5::util::md_speclink!("_Toc3901205")]
pub struct MDisconnect<'i> {
pub reason_code: DisconnectReasonCode,
Expand Down
2 changes: 1 addition & 1 deletion mqtt-format/src/v5/packets/pingreq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::v5::write::WResult;
use crate::v5::write::WriteMqttPacket;
use crate::v5::MResult;

#[derive(Debug)]
#[derive(Debug, PartialEq)]
#[doc = crate::v5::util::md_speclink!("_Toc3901195")]
pub struct MPingreq;

Expand Down
2 changes: 1 addition & 1 deletion mqtt-format/src/v5/packets/pingresp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::v5::write::WResult;
use crate::v5::write::WriteMqttPacket;
use crate::v5::MResult;

#[derive(Debug)]
#[derive(Debug, PartialEq)]
#[doc = crate::v5::util::md_speclink!("_Toc3901200")]
pub struct MPingresp;

Expand Down
2 changes: 1 addition & 1 deletion mqtt-format/src/v5/packets/puback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ define_properties!(
}
);

#[derive(Debug)]
#[derive(Debug, PartialEq)]
#[doc = crate::v5::util::md_speclink!("_Toc3901121")]
pub struct MPuback<'i> {
pub packet_identifier: PacketIdentifier,
Expand Down
2 changes: 1 addition & 1 deletion mqtt-format/src/v5/packets/pubcomp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ crate::v5::properties::define_properties! {
}
}

#[derive(Debug)]
#[derive(Debug, PartialEq)]
#[doc = crate::v5::util::md_speclink!("_Toc3901151")]
pub struct MPubcomp<'i> {
pub packet_identifier: PacketIdentifier,
Expand Down
2 changes: 1 addition & 1 deletion mqtt-format/src/v5/packets/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::v5::write::WResult;
use crate::v5::write::WriteMqttPacket;
use crate::v5::MResult;

#[derive(Debug)]
#[derive(Debug, PartialEq)]
#[doc = crate::v5::util::md_speclink!("_Toc3901100")]
pub struct MPublish<'i> {
pub duplicate: bool,
Expand Down
2 changes: 1 addition & 1 deletion mqtt-format/src/v5/packets/pubrec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ crate::v5::properties::define_properties![
}
];

#[derive(Debug)]
#[derive(Debug, PartialEq)]
#[doc = crate::v5::util::md_speclink!("_Toc3901131")]
pub struct MPubrec<'i> {
pub packet_identifier: PacketIdentifier,
Expand Down
2 changes: 1 addition & 1 deletion mqtt-format/src/v5/packets/pubrel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ define_properties!(
}
);

#[derive(Debug)]
#[derive(Debug, PartialEq)]
#[doc = crate::v5::util::md_speclink!("_Toc3901141")]
pub struct MPubrel<'i> {
pub packet_identifier: PacketIdentifier,
Expand Down
2 changes: 1 addition & 1 deletion mqtt-format/src/v5/packets/suback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ crate::v5::properties::define_properties! {
}
}

#[derive(Debug)]
#[derive(Debug, PartialEq)]
#[doc = crate::v5::util::md_speclink!("_Toc3901171")]
pub struct MSuback<'i> {
pub packet_identifier: PacketIdentifier,
Expand Down
12 changes: 9 additions & 3 deletions mqtt-format/src/v5/packets/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ define_properties! {
}
}

#[derive(Debug, num_enum::TryFromPrimitive, num_enum::IntoPrimitive, Clone, Copy)]
#[derive(Debug, num_enum::TryFromPrimitive, num_enum::IntoPrimitive, Clone, Copy, PartialEq)]
#[repr(u8)]
pub enum RetainHandling {
SendRetainedMessagesAlways = 0,
SendRetainedMessagesOnNewSubscribe = 1,
DoNotSendRetainedMessages = 2,
}

#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub struct SubscriptionOptions {
pub quality_of_service: QualityOfService,
pub no_local: bool,
Expand Down Expand Up @@ -85,7 +85,7 @@ impl SubscriptionOptions {
}
}

#[derive(Debug)]
#[derive(Debug, PartialEq)]
#[doc = crate::v5::util::md_speclink!("_Toc3901161")]
pub struct Subscription<'i> {
pub topic_filter: &'i str,
Expand Down Expand Up @@ -116,6 +116,12 @@ pub struct Subscriptions<'i> {
start: &'i [u8],
}

impl<'i> core::cmp::PartialEq for Subscriptions<'i> {
fn eq(&self, other: &Self) -> bool {
self.iter().eq(other.iter())
}
}

impl<'i> core::fmt::Debug for Subscriptions<'i> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("Subscriptions").finish()
Expand Down
2 changes: 1 addition & 1 deletion mqtt-format/src/v5/packets/unsuback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ crate::v5::properties::define_properties! {
}
}

#[derive(Debug)]
#[derive(Debug, PartialEq)]
#[doc = crate::v5::util::md_speclink!("_Toc3901187")]
pub struct MUnsuback<'i> {
pub packet_identifier: PacketIdentifier,
Expand Down
10 changes: 8 additions & 2 deletions mqtt-format/src/v5/packets/unsubscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ pub struct Unsubscriptions<'i> {
start: &'i [u8],
}

impl<'i> core::cmp::PartialEq for Unsubscriptions<'i> {
fn eq(&self, other: &Self) -> bool {
self.iter().eq(other.iter())
}
}

impl<'i> core::fmt::Debug for Unsubscriptions<'i> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("Unsubscriptions").finish()
Expand Down Expand Up @@ -95,7 +101,7 @@ impl<'i> Iterator for UnsubscriptionsIter<'i> {
}
}

#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub struct Unsubscription<'i> {
pub topic_filter: &'i str,
}
Expand All @@ -115,7 +121,7 @@ impl<'i> Unsubscription<'i> {
}
}

#[derive(Debug)]
#[derive(Debug, PartialEq)]
#[doc = crate::v5::util::md_speclink!("_Toc3901179")]
pub struct MUnsubscribe<'i> {
pub packet_identifier: PacketIdentifier,
Expand Down
2 changes: 1 addition & 1 deletion mqtt-format/src/v5/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ macro_rules! define_properties {
$(
#[doc = $crate::v5::util::md_speclink!($anker)]
)?
#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub struct $name < $lt > {
$(
$(
Expand Down
4 changes: 2 additions & 2 deletions mqtt-format/src/v5/reason_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ macro_rules! make_combined_reason_code {
}) => {
#[derive(num_enum::TryFromPrimitive, num_enum::IntoPrimitive)]
#[repr(u8)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum $name {
$( $reason_code_name = <$reason_code_type>::CODE ),*
}
Expand Down Expand Up @@ -46,7 +46,7 @@ pub(crate) use make_combined_reason_code;

macro_rules! define_reason_code {
($name:ident => $code:literal) => {
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct $name;
impl $name {
pub const CODE: u8 = $code;
Expand Down
12 changes: 9 additions & 3 deletions mqtt-format/src/v5/variable_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::write::WResult;
use super::write::WriteMqttPacket;
use super::MResult;

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PacketIdentifier(pub u16);

impl PacketIdentifier {
Expand Down Expand Up @@ -61,7 +61,7 @@ macro_rules! define_properties {
$(,)?
]) => {
$(
#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub struct $name < $($tylt)? >(pub $(& $lt)? $kind);

impl<'lt $(, $tylt)?> MqttProperties<'lt> for $name < $($tylt)? >
Expand Down Expand Up @@ -103,7 +103,7 @@ macro_rules! define_properties {
}
)*

#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub enum Property<'i> {
$(
$name ( $name $(< $tylt >)? ),
Expand Down Expand Up @@ -280,6 +280,12 @@ define_properties! {[

pub struct UserProperties<'i>(pub &'i [u8]);

impl<'i> core::cmp::PartialEq for UserProperties<'i> {
fn eq(&self, other: &Self) -> bool {
self.iter().eq(other.iter())
}
}

impl<'i> core::fmt::Debug for UserProperties<'i> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_tuple("UserProperties").finish()
Expand Down

0 comments on commit 0b90438

Please sign in to comment.