From bc0a5328c3bea88b95d10246af2d4c7a40ad46e6 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Mon, 15 Jul 2024 18:29:32 +0200 Subject: [PATCH 1/4] Simplifying struct bounds --- src/config.rs | 4 ++-- src/mqtt_client.rs | 14 ++------------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/config.rs b/src/config.rs index 34b705e..4549549 100644 --- a/src/config.rs +++ b/src/config.rs @@ -16,7 +16,7 @@ pub enum BufferConfig { } #[derive(Debug)] -pub(crate) struct Config<'a, Broker: crate::Broker> { +pub(crate) struct Config<'a, Broker> { pub(crate) broker: Broker, pub(crate) rx_buffer: &'a mut [u8], pub(crate) tx_buffer: &'a mut [u8], @@ -30,7 +30,7 @@ pub(crate) struct Config<'a, Broker: crate::Broker> { /// Configuration specifying the operational state of the MQTT client. #[derive(Debug)] -pub struct ConfigBuilder<'a, Broker: crate::Broker> { +pub struct ConfigBuilder<'a, Broker> { buffer: &'a mut [u8], broker: Broker, rx_config: Option, diff --git a/src/mqtt_client.rs b/src/mqtt_client.rs index a869f64..e768eaa 100644 --- a/src/mqtt_client.rs +++ b/src/mqtt_client.rs @@ -260,12 +260,7 @@ impl From> for Error { } /// The client that can be used for interacting with the MQTT broker. -pub struct MqttClient< - 'buf, - TcpStack: TcpClientStack, - Clock: embedded_time::Clock, - Broker: crate::Broker, -> { +pub struct MqttClient<'buf, TcpStack: TcpClientStack, Clock: embedded_time::Clock, Broker> { sm: sm::StateMachine>, network: InterfaceHolder<'buf, TcpStack>, will: Option>, @@ -673,12 +668,7 @@ impl<'buf, TcpStack: TcpClientStack, Clock: embedded_time::Clock, Broker: crate: /// # Note /// To connect and maintain an MQTT connection, the `Minimq::poll()` method must be called /// regularly. -pub struct Minimq<'buf, TcpStack, Clock, Broker> -where - TcpStack: TcpClientStack, - Clock: embedded_time::Clock, - Broker: crate::Broker, -{ +pub struct Minimq<'buf, TcpStack: TcpClientStack, Clock: embedded_time::Clock, Broker> { client: MqttClient<'buf, TcpStack, Clock, Broker>, packet_reader: PacketReader<'buf>, } From 98c35a371c44583cf15577d15f24c72422a4e35e Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 16 Jul 2024 12:53:32 +0200 Subject: [PATCH 2/4] Further simplifying struct bounds --- src/broker.rs | 4 ++-- src/packets.rs | 4 ++-- src/publication.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/broker.rs b/src/broker.rs index 9c5e32b..95eef32 100644 --- a/src/broker.rs +++ b/src/broker.rs @@ -14,13 +14,13 @@ pub trait Broker { /// A broker that is specified using a qualified domain-name. The name will be resolved at some /// point in the future. #[derive(Debug)] -pub struct NamedBroker { +pub struct NamedBroker { raw: heapless::String, resolver: R, addr: SocketAddr, } -impl NamedBroker { +impl NamedBroker { /// Construct a new named broker. /// /// # Args diff --git a/src/packets.rs b/src/packets.rs index 9471c06..4e52dc5 100644 --- a/src/packets.rs +++ b/src/packets.rs @@ -88,7 +88,7 @@ pub struct ConnAck<'a> { /// An MQTT PUBLISH packet, containing data to be sent or received. #[derive(Serialize)] -pub struct Pub<'a, P: crate::publication::ToPayload> { +pub struct Pub<'a, P> { /// The topic that the message was received on. pub topic: Utf8String<'a>, @@ -115,7 +115,7 @@ pub struct Pub<'a, P: crate::publication::ToPayload> { pub dup: bool, } -impl<'a, P: crate::publication::ToPayload> core::fmt::Debug for Pub<'a, P> { +impl<'a, P> core::fmt::Debug for Pub<'a, P> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("Pub") .field("topic", &self.topic) diff --git a/src/publication.rs b/src/publication.rs index 10c4aff..25f49fc 100644 --- a/src/publication.rs +++ b/src/publication.rs @@ -73,7 +73,7 @@ impl Result> ToPayload for DeferredPublicat /// It is expected that the user provide a topic either by directly specifying a publication topic /// in [Publication::topic], or by parsing a topic from the [Property::ResponseTopic] property /// contained within received properties by using the [Publication::reply] API. -pub struct Publication<'a, P: ToPayload> { +pub struct Publication<'a, P> { topic: Option<&'a str>, properties: Properties<'a>, qos: QoS, From f0381fb225ebf0a7f4c04b17629620fe0ecd1ca3 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 16 Jul 2024 13:09:22 +0200 Subject: [PATCH 3/4] Further relaxing --- src/message_types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/message_types.rs b/src/message_types.rs index bfc26ca..2a51a9b 100644 --- a/src/message_types.rs +++ b/src/message_types.rs @@ -43,7 +43,7 @@ impl<'a> ControlPacket for ConnAck<'a> { const MESSAGE_TYPE: MessageType = MessageType::ConnAck; } -impl<'a, P: crate::publication::ToPayload> Pub<'a, P> { +impl<'a, P> Pub<'a, P> { pub fn fixed_header_flags(&self) -> u8 { *0u8.set_bits(1..=2, self.qos as u8) .set_bit(0, self.retain == Retain::Retained) From e76157ebb52ba9a364902f397d691b10bbba420c Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 16 Jul 2024 13:14:10 +0200 Subject: [PATCH 4/4] Relaxing further bounds --- src/publication.rs | 6 +++--- src/varint.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/publication.rs b/src/publication.rs index 25f49fc..3e88ef4 100644 --- a/src/publication.rs +++ b/src/publication.rs @@ -44,17 +44,17 @@ impl ToPayload for &[u8; N] { /// # Note /// This is "deferred" because the closure will only be called once the publication is actually /// sent. -pub struct DeferredPublication Result> { +pub struct DeferredPublication { func: F, } -impl Result> DeferredPublication { +impl Result> DeferredPublication { pub fn new<'a>(func: F) -> Publication<'a, Self> { Publication::new(Self { func }) } } -impl Result> ToPayload for DeferredPublication { +impl Result> ToPayload for DeferredPublication { type Error = E; fn serialize(self, buffer: &mut [u8]) -> Result { (self.func)(buffer) diff --git a/src/varint.rs b/src/varint.rs index 6be3db6..5235937 100644 --- a/src/varint.rs +++ b/src/varint.rs @@ -38,7 +38,7 @@ impl VarintWriter for VarintBuffer { struct VarintVisitor; -struct VarintParser<'de, T: serde::de::SeqAccess<'de>> { +struct VarintParser<'de, T> { seq: T, _data: core::marker::PhantomData<&'de ()>, }