From d346eb7c72f63d9a4a865327e40298917d6c3131 Mon Sep 17 00:00:00 2001 From: ivmarkov Date: Tue, 23 Jan 2024 12:11:37 +0000 Subject: [PATCH] Connection error can only be referenced --- src/mqtt/client.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/mqtt/client.rs b/src/mqtt/client.rs index 3dc7cda..ff27443 100644 --- a/src/mqtt/client.rs +++ b/src/mqtt/client.rs @@ -38,14 +38,14 @@ pub enum QoS { pub type MessageId = u32; pub trait Event: ErrorType { - fn payload(&self) -> Result, Self::Error>; + fn payload(&self) -> EventPayload<'_, Self::Error>; } impl Event for &E where E: Event, { - fn payload(&self) -> Result, Self::Error> { + fn payload(&self) -> EventPayload<'_, Self::Error> { (*self).payload() } } @@ -54,15 +54,14 @@ impl Event for &mut E where E: Event, { - fn payload(&self) -> Result, Self::Error> { + fn payload(&self) -> EventPayload<'_, Self::Error> { (**self).payload() } } #[derive(Clone, PartialEq, Eq, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))] -pub enum EventPayload<'a> { +pub enum EventPayload<'a, E> { BeforeConnect, Connected(bool), Disconnected, @@ -76,9 +75,13 @@ pub enum EventPayload<'a> { details: Details, }, Deleted(MessageId), + Error(&'a E), } -impl<'a> Display for EventPayload<'a> { +impl<'a, E> Display for EventPayload<'a, E> +where + E: Debug, +{ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { Self::BeforeConnect => write!(f, "BeforeConnect"), @@ -97,6 +100,7 @@ impl<'a> Display for EventPayload<'a> { "Received {{ id: {id}, topic: {topic:?}, data: {data:?}, details: {details:?} }}" ), Self::Deleted(message_id) => write!(f, "Deleted({message_id})"), + Self::Error(error) => write!(f, "Error({error:?})"), } } }