Skip to content

Commit

Permalink
Merge pull request #163 from quartiq/issue/162/struct-bounds
Browse files Browse the repository at this point in the history
Simplifying struct bounds
  • Loading branch information
jordens authored Jul 16, 2024
2 parents 2b8b2ee + e76157e commit ce94255
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R: Dns, const T: usize = 253> {
pub struct NamedBroker<R, const T: usize = 253> {
raw: heapless::String<T>,
resolver: R,
addr: SocketAddr,
}

impl<R: Dns, const T: usize> NamedBroker<R, T> {
impl<R, const T: usize> NamedBroker<R, T> {
/// Construct a new named broker.
///
/// # Args
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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<BufferConfig>,
Expand Down
2 changes: 1 addition & 1 deletion src/message_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 2 additions & 12 deletions src/mqtt_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,7 @@ impl<E> From<sm::Error<MinimqError>> for Error<E> {
}

/// 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<ClientContext<'buf, Clock>>,
network: InterfaceHolder<'buf, TcpStack>,
will: Option<SerializedWill<'buf>>,
Expand Down Expand Up @@ -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>,
}
Expand Down
4 changes: 2 additions & 2 deletions src/packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,

Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/publication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ impl<const N: usize> ToPayload for &[u8; N] {
/// # Note
/// This is "deferred" because the closure will only be called once the publication is actually
/// sent.
pub struct DeferredPublication<E, F: FnOnce(&mut [u8]) -> Result<usize, E>> {
pub struct DeferredPublication<F> {
func: F,
}

impl<E, F: FnOnce(&mut [u8]) -> Result<usize, E>> DeferredPublication<E, F> {
impl<E, F: FnOnce(&mut [u8]) -> Result<usize, E>> DeferredPublication<F> {
pub fn new<'a>(func: F) -> Publication<'a, Self> {
Publication::new(Self { func })
}
}

impl<E, F: FnOnce(&mut [u8]) -> Result<usize, E>> ToPayload for DeferredPublication<E, F> {
impl<E, F: FnOnce(&mut [u8]) -> Result<usize, E>> ToPayload for DeferredPublication<F> {
type Error = E;
fn serialize(self, buffer: &mut [u8]) -> Result<usize, E> {
(self.func)(buffer)
Expand All @@ -73,7 +73,7 @@ impl<E, F: FnOnce(&mut [u8]) -> Result<usize, E>> 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,
Expand Down
2 changes: 1 addition & 1 deletion src/varint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()>,
}
Expand Down

0 comments on commit ce94255

Please sign in to comment.