From bcc6721257889f85f57af1b40351540585ffd41d Mon Sep 17 00:00:00 2001 From: hozan23 Date: Thu, 27 Jun 2024 03:52:18 +0200 Subject: Remove redundant type aliases --- core/src/event.rs | 5 ++--- core/src/pubsub.rs | 17 ++++++++--------- 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'core') diff --git a/core/src/event.rs b/core/src/event.rs index 1632df3..a4e356b 100644 --- a/core/src/event.rs +++ b/core/src/event.rs @@ -14,7 +14,6 @@ use crate::{async_runtime::lock::Mutex, util::random_32, Result}; const CHANNEL_BUFFER_SIZE: usize = 1000; -pub type ArcEventSys = Arc>; pub type EventListenerID = u32; type Listeners = HashMap>>>; @@ -84,7 +83,7 @@ where T: std::hash::Hash + Eq + std::fmt::Debug + Clone, { /// Creates a new [`EventSys`] - pub fn new() -> ArcEventSys { + pub fn new() -> Arc> { Arc::new(Self { listeners: Mutex::new(HashMap::new()), listener_buffer_size: CHANNEL_BUFFER_SIZE, @@ -101,7 +100,7 @@ where /// starts to consume the buffered events. /// /// If `size` is zero, this function will panic. - pub fn with_buffer_size(size: usize) -> ArcEventSys { + pub fn with_buffer_size(size: usize) -> Arc> { Arc::new(Self { listeners: Mutex::new(HashMap::new()), listener_buffer_size: size, diff --git a/core/src/pubsub.rs b/core/src/pubsub.rs index 09b62ea..7aa4936 100644 --- a/core/src/pubsub.rs +++ b/core/src/pubsub.rs @@ -7,7 +7,6 @@ use crate::{async_runtime::lock::Mutex, util::random_32, Result}; const CHANNEL_BUFFER_SIZE: usize = 1000; -pub type ArcPublisher = Arc>; pub type SubscriptionID = u32; /// A simple publish-subscribe system. @@ -36,7 +35,7 @@ pub struct Publisher { impl Publisher { /// Creates a new [`Publisher`] - pub fn new() -> ArcPublisher { + pub fn new() -> Arc> { Arc::new(Self { subs: Mutex::new(HashMap::new()), subscription_buffer_size: CHANNEL_BUFFER_SIZE, @@ -53,7 +52,7 @@ impl Publisher { /// the buffered messages. /// /// If `size` is zero, this function will panic. - pub fn with_buffer_size(size: usize) -> ArcPublisher { + pub fn with_buffer_size(size: usize) -> Arc> { Arc::new(Self { subs: Mutex::new(HashMap::new()), subscription_buffer_size: size, @@ -79,7 +78,7 @@ impl Publisher { sub } - /// Unsubscribes from the publisher + /// Unsubscribes by providing subscription id pub async fn unsubscribe(self: &Arc, id: &SubscriptionID) { self.subs.lock().await.remove(id); } @@ -114,14 +113,14 @@ impl Publisher { pub struct Subscription { id: SubscriptionID, recv_chan: async_channel::Receiver, - publisher: ArcPublisher, + publisher: Arc>, } impl Subscription { - /// Creates a new Subscription + /// Creates a new [`Subscription`] pub fn new( id: SubscriptionID, - publisher: ArcPublisher, + publisher: Arc>, recv_chan: async_channel::Receiver, ) -> Subscription { Self { @@ -131,13 +130,13 @@ impl Subscription { } } - /// Receive a message from the Publisher + /// Receive a message from the [`Publisher`] pub async fn recv(&self) -> Result { let msg = self.recv_chan.recv().await?; Ok(msg) } - /// Unsubscribe from the Publisher + /// Unsubscribe from the [`Publisher`] pub async fn unsubscribe(&self) { self.publisher.unsubscribe(&self.id).await; } -- cgit v1.2.3