From f6527c9ec4a752dfe969a9522a3669a5dbfe1bc3 Mon Sep 17 00:00:00 2001 From: Devdutt Shenoi Date: Wed, 10 Aug 2022 09:52:31 +0530 Subject: [PATCH] feat(`AsyncClient`): remove code exposing flume errors in `ClientError` (#420) * feat: remove code exposing flume errors in `ClientError` to simplify API surfaces and not reveal irrelevant internal details * docs: add changelog entry Signed-off-by: Devdutt Shenoi Issue: 419 Attribute: @de-sh --- CHANGELOG.md | 7 +++++++ rumqttc/src/client.rs | 24 +++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f727cdf..41cdc9e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +---------------- +rumqttc +----------- +- Change variants in `ClientError` to not expose dependence on flume/`SendError`. + +----------- + ### R13 ---------------- rumqttc v0.13.0 diff --git a/rumqttc/src/client.rs b/rumqttc/src/client.rs index ef457f64..348deef4 100644 --- a/rumqttc/src/client.rs +++ b/rumqttc/src/client.rs @@ -13,15 +13,33 @@ use tokio::runtime::Runtime; #[derive(Debug, thiserror::Error)] pub enum ClientError { #[error("Failed to send cancel request to eventloop")] - Cancel(#[from] SendError<()>), + Cancel, #[error("Failed to send mqtt requests to eventloop")] - Request(#[from] SendError), + Request(Request), #[error("Failed to send mqtt requests to eventloop")] - TryRequest(#[from] TrySendError), + TryRequest(Request), #[error("Serialization error: {0}")] Mqtt4(#[from] mqttbytes::Error), } +impl From> for ClientError { + fn from(_: SendError<()>) -> Self { + Self::Cancel + } +} + +impl From> for ClientError { + fn from(e: SendError) -> Self { + Self::Request(e.into_inner()) + } +} + +impl From> for ClientError { + fn from(e: TrySendError) -> Self { + Self::TryRequest(e.into_inner()) + } +} + /// `AsyncClient` to communicate with MQTT `Eventloop` /// This is cloneable and can be used to asynchronously Publish, Subscribe. #[derive(Clone, Debug)]