From 22283dc7caa42ae31a23cfad93d2f16465b9b031 Mon Sep 17 00:00:00 2001 From: Alex Mikhalev Date: Sun, 27 Dec 2020 13:44:05 -0700 Subject: [PATCH] Rename RecvError to SubscriptionError --- src/lib.rs | 6 +++--- src/subscription.rs | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 880625e..3d13eee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ use broker_task::{ }; pub use message::Message; pub use publication::{Publication, PublishError}; -pub use subscription::{RecvError, Subscription}; +pub use subscription::{Subscription, SubscriptionError}; use futures::executor::block_on; use tokio::sync::mpsc; @@ -105,7 +105,7 @@ mod test { assert_eq!(sub.recv_blocking(), Ok(TestMsg(10))); assert_eq!(sub.recv_blocking(), Ok(TestMsg(20))); assert_eq!(sub.recv_blocking(), Ok(TestMsg(30))); - assert_eq!(sub.try_recv(), Err(RecvError::Empty)); + assert_eq!(sub.try_recv(), Err(SubscriptionError::Empty)); }) .await .unwrap(); @@ -127,6 +127,6 @@ mod test { assert_eq!(sub.recv().await, Ok(TestMsg(10))); assert_eq!(sub.recv().await, Ok(TestMsg(20))); assert_eq!(sub.recv().await, Ok(TestMsg(30))); - assert_eq!(sub.try_recv(), Err(RecvError::Empty)); + assert_eq!(sub.try_recv(), Err(SubscriptionError::Empty)); } } diff --git a/src/subscription.rs b/src/subscription.rs index 692b1fb..27449a1 100644 --- a/src/subscription.rs +++ b/src/subscription.rs @@ -5,27 +5,27 @@ use crate::message::Message; #[derive(Clone, Debug, PartialEq)] #[non_exhaustive] -pub enum RecvError { +pub enum SubscriptionError { Empty, Closed, Lagged, } -impl From for RecvError { +impl From for SubscriptionError { fn from(err: broadcast::error::RecvError) -> Self { match err { - broadcast::error::RecvError::Closed => RecvError::Closed, - broadcast::error::RecvError::Lagged(_) => RecvError::Lagged, + broadcast::error::RecvError::Closed => SubscriptionError::Closed, + broadcast::error::RecvError::Lagged(_) => SubscriptionError::Lagged, } } } -impl From for RecvError { +impl From for SubscriptionError { fn from(err: broadcast::error::TryRecvError) -> Self { match err { - broadcast::error::TryRecvError::Empty => RecvError::Empty, - broadcast::error::TryRecvError::Closed => RecvError::Closed, - broadcast::error::TryRecvError::Lagged(_) => RecvError::Lagged, + broadcast::error::TryRecvError::Empty => SubscriptionError::Empty, + broadcast::error::TryRecvError::Closed => SubscriptionError::Closed, + broadcast::error::TryRecvError::Lagged(_) => SubscriptionError::Lagged, } } } @@ -42,15 +42,15 @@ impl Subscription { } impl Subscription { - pub async fn recv(&mut self) -> Result { + pub async fn recv(&mut self) -> Result { Ok(self.receiver.recv().await?) } - pub fn recv_blocking(&mut self) -> Result { + pub fn recv_blocking(&mut self) -> Result { block_on(self.recv()) } - pub fn try_recv(&mut self) -> Result { + pub fn try_recv(&mut self) -> Result { Ok(self.receiver.try_recv()?) } }