From 0299a6064d31752ed50c49db1010fb945c5ad3d5 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Tue, 15 Mar 2022 14:54:57 -0700 Subject: [PATCH] feat: add `#[must_use]` to constructors (#45) Signed-off-by: Eliza Weisman --- src/mpsc/async_impl.rs | 5 +++++ src/mpsc/blocking.rs | 6 ++++++ src/static_thingbuf.rs | 2 ++ src/thingbuf.rs | 2 ++ 4 files changed, 15 insertions(+) diff --git a/src/mpsc/async_impl.rs b/src/mpsc/async_impl.rs index f7cfe27..0d370a7 100644 --- a/src/mpsc/async_impl.rs +++ b/src/mpsc/async_impl.rs @@ -24,6 +24,7 @@ feature! { /// This channel will use the [default recycling policy]. /// /// [recycling policy]: crate::recycling::DefaultRecycle + #[must_use] pub fn channel(capacity: usize) -> (Sender, Receiver) { with_recycle(capacity, recycling::DefaultRecycle::new()) } @@ -32,6 +33,7 @@ feature! { /// channel with the provided capacity and [recycling policy]. /// /// [recycling policy]: crate::recycling::Recycle + #[must_use] pub fn with_recycle>(capacity: usize, recycle: R) -> (Sender, Receiver) { assert!(capacity > 0); let inner = Arc::new(Inner { @@ -636,6 +638,7 @@ feature! { /// } /// ``` /// [`split`]: StaticChannel::split + #[must_use] pub const fn new() -> Self { Self { core: ChannelCore::new(CAPACITY), @@ -658,6 +661,7 @@ feature! { /// # Panics /// /// If the channel has already been split. + #[must_use] pub fn split(&'static self) -> (StaticSender, StaticReceiver) { self.try_split().expect("channel already split") } @@ -668,6 +672,7 @@ feature! { /// A static channel can only be split a single time. If /// [`StaticChannel::split`] or [`StaticChannel::try_split`] have been /// called previously, this method returns `None`. + #[must_use] pub fn try_split(&'static self) -> Option<(StaticSender, StaticReceiver)> { self.is_split .compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst) diff --git a/src/mpsc/blocking.rs b/src/mpsc/blocking.rs index 287986e..fa55b72 100644 --- a/src/mpsc/blocking.rs +++ b/src/mpsc/blocking.rs @@ -24,6 +24,7 @@ use errors::*; /// This channel will use the [default recycling policy]. /// /// [recycling policy]: crate::recycling::DefaultRecycle +#[must_use] pub fn channel(capacity: usize) -> (Sender, Receiver) { with_recycle(capacity, recycling::DefaultRecycle::new()) } @@ -32,6 +33,7 @@ pub fn channel(capacity: usize) -> (Sender, Receiver) /// the provided [recycling policy]. /// /// [recycling policy]: crate::recycling::Recycle +#[must_use] pub fn with_recycle>( capacity: usize, recycle: R, @@ -48,6 +50,7 @@ pub fn with_recycle>( let rx = Receiver { inner }; (tx, rx) } + /// Synchronously receives values from associated [`Sender`]s. /// /// Instances of this struct are created by the [`channel`] and @@ -184,6 +187,7 @@ feature! { /// /// [async]: crate::mpsc::StaticChannel /// [`split`]: StaticChannel::split + #[must_use] pub const fn new() -> Self { Self { core: ChannelCore::new(CAPACITY), @@ -206,6 +210,7 @@ feature! { /// # Panics /// /// If the channel has already been split. + #[must_use] pub fn split(&'static self) -> (StaticSender, StaticReceiver) { self.try_split().expect("channel already split") } @@ -216,6 +221,7 @@ feature! { /// A static channel can only be split a single time. If /// [`StaticChannel::split`] or [`StaticChannel::try_split`] have been /// called previously, this method returns `None`. + #[must_use] pub fn try_split(&'static self) -> Option<(StaticSender, StaticReceiver)> { self.is_split .compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst) diff --git a/src/static_thingbuf.rs b/src/static_thingbuf.rs index 1f93a65..2635bc6 100644 --- a/src/static_thingbuf.rs +++ b/src/static_thingbuf.rs @@ -207,6 +207,7 @@ impl StaticThingBuf { /// This queue will use the [default recycling policy]. /// /// [recycling policy]: crate::recycling::DefaultRecycle + #[must_use] pub const fn new() -> Self { Self::with_recycle(recycling::DefaultRecycle::new()) } @@ -217,6 +218,7 @@ impl StaticThingBuf { /// the provided [recycling policy]. /// /// [recycling policy]: crate::recycling::Recycle + #[must_use] pub const fn with_recycle(recycle: R) -> Self { StaticThingBuf { core: Core::new(CAP), diff --git a/src/thingbuf.rs b/src/thingbuf.rs index ae1dc42..b38e3db 100644 --- a/src/thingbuf.rs +++ b/src/thingbuf.rs @@ -190,6 +190,7 @@ pub struct ThingBuf { impl ThingBuf { /// Returns a new `ThingBuf` with space for `capacity` elements. + #[must_use] pub fn new(capacity: usize) -> Self { Self::with_recycle(capacity, recycling::DefaultRecycle::new()) } @@ -300,6 +301,7 @@ where /// the provided [recycling policy]. /// /// [recycling policy]: crate::recycling::Recycle + #[must_use] pub fn with_recycle(capacity: usize, recycle: R) -> Self { assert!(capacity > 0); Self {