Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use_serde = ["dep:serde", "enumset/serde", "heapless/serde"]
use_strum = ["strum", "strum_macros"]
use_numenum = ["num_enum"]
defmt = ["dep:defmt", "heapless/defmt-03", "embedded-io/defmt-03", "embedded-io-async/defmt-03"]
mqtt_protocol_v5 = []

[dependencies]
heapless = { version = "0.8" }
Expand Down
2 changes: 2 additions & 0 deletions src/mqtt.rs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pub mod client;
#[cfg(feature = "mqtt_protocol_v5")]
pub mod client5;
35 changes: 34 additions & 1 deletion src/mqtt/client.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
use core::fmt::{self, Debug, Display, Formatter};
#[cfg(all(feature = "mqtt_protocol_v5", feature = "std"))]
use std::vec::Vec;

#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(feature = "use_serde")]
use serde::{Deserialize, Serialize};

#[cfg(feature = "mqtt_protocol_v5")]
use crate::mqtt::client5::MessageMetadata;
#[cfg(all(feature = "mqtt_protocol_v5", feature = "std"))]
use crate::mqtt::client5::UserPropertyItem;

pub trait ErrorType {
type Error: Debug;
}

pub trait EventHandlerType {
type Handler;
}

impl<E> ErrorType for &E
where
E: ErrorType,
Expand Down Expand Up @@ -39,6 +50,10 @@ pub type MessageId = u32;

pub trait Event: ErrorType {
fn payload(&self) -> EventPayload<'_, Self::Error>;
#[cfg(feature = "mqtt_protocol_v5")]
fn metadata<'a>(&self) -> Option<MessageMetadata<'a>>;
#[cfg(all(feature = "mqtt_protocol_v5", feature = "std"))]
fn user_properties<'a>(&self) -> Result<Vec<UserPropertyItem<'a>>, Self::Error>;
}

impl<E> Event for &E
Expand All @@ -48,6 +63,14 @@ where
fn payload(&self) -> EventPayload<'_, Self::Error> {
(*self).payload()
}
#[cfg(feature = "mqtt_protocol_v5")]
fn metadata<'a>(&self) -> Option<MessageMetadata<'a>> {
(*self).metadata()
}
#[cfg(all(feature = "mqtt_protocol_v5", feature = "std"))]
fn user_properties<'a>(&self) -> Result<Vec<UserPropertyItem<'a>>, Self::Error> {
(*self).user_properties()
}
}

impl<E> Event for &mut E
Expand All @@ -57,10 +80,20 @@ where
fn payload(&self) -> EventPayload<'_, Self::Error> {
(**self).payload()
}

#[cfg(feature = "mqtt_protocol_v5")]
fn metadata<'a>(&self) -> Option<MessageMetadata<'a>> {
(**self).metadata()
}

#[cfg(all(feature = "mqtt_protocol_v5", feature = "std"))]
fn user_properties<'a>(&self) -> Result<Vec<UserPropertyItem<'a>>, Self::Error> {
(**self).user_properties()
}
}

#[derive(Clone, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Clone, PartialEq, Eq, Debug)]
pub enum EventPayload<'a, E> {
BeforeConnect,
Connected(bool),
Expand Down
Loading