Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add #[must_use] to constructors #45

Merged
merged 2 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/mpsc/async_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ feature! {
/// This channel will use the [default recycling policy].
///
/// [recycling policy]: crate::recycling::DefaultRecycle
#[must_use]
pub fn channel<T: Default + Clone>(capacity: usize) -> (Sender<T>, Receiver<T>) {
with_recycle(capacity, recycling::DefaultRecycle::new())
}
Expand All @@ -32,6 +33,7 @@ feature! {
/// channel with the provided capacity and [recycling policy].
///
/// [recycling policy]: crate::recycling::Recycle
#[must_use]
pub fn with_recycle<T, R: Recycle<T>>(capacity: usize, recycle: R) -> (Sender<T, R>, Receiver<T, R>) {
assert!(capacity > 0);
let inner = Arc::new(Inner {
Expand Down Expand Up @@ -636,6 +638,7 @@ feature! {
/// }
/// ```
/// [`split`]: StaticChannel::split
#[must_use]
pub const fn new() -> Self {
Self {
core: ChannelCore::new(CAPACITY),
Expand All @@ -658,6 +661,7 @@ feature! {
/// # Panics
///
/// If the channel has already been split.
#[must_use]
pub fn split(&'static self) -> (StaticSender<T, R>, StaticReceiver<T, R>) {
self.try_split().expect("channel already split")
}
Expand All @@ -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<T, R>, StaticReceiver<T, R>)> {
self.is_split
.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst)
Expand Down
6 changes: 6 additions & 0 deletions src/mpsc/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use errors::*;
/// This channel will use the [default recycling policy].
///
/// [recycling policy]: crate::recycling::DefaultRecycle
#[must_use]
pub fn channel<T: Default + Clone>(capacity: usize) -> (Sender<T>, Receiver<T>) {
with_recycle(capacity, recycling::DefaultRecycle::new())
}
Expand All @@ -32,6 +33,7 @@ pub fn channel<T: Default + Clone>(capacity: usize) -> (Sender<T>, Receiver<T>)
/// the provided [recycling policy].
///
/// [recycling policy]: crate::recycling::Recycle
#[must_use]
pub fn with_recycle<T, R: Recycle<T>>(
capacity: usize,
recycle: R,
Expand All @@ -48,6 +50,7 @@ pub fn with_recycle<T, R: Recycle<T>>(
let rx = Receiver { inner };
(tx, rx)
}

/// Synchronously receives values from associated [`Sender`]s.
///
/// Instances of this struct are created by the [`channel`] and
Expand Down Expand Up @@ -184,6 +187,7 @@ feature! {
///
/// [async]: crate::mpsc::StaticChannel
/// [`split`]: StaticChannel::split
#[must_use]
pub const fn new() -> Self {
Self {
core: ChannelCore::new(CAPACITY),
Expand All @@ -206,6 +210,7 @@ feature! {
/// # Panics
///
/// If the channel has already been split.
#[must_use]
pub fn split(&'static self) -> (StaticSender<T, R>, StaticReceiver<T, R>) {
self.try_split().expect("channel already split")
}
Expand All @@ -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<T, R>, StaticReceiver<T, R>)> {
self.is_split
.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst)
Expand Down
2 changes: 2 additions & 0 deletions src/static_thingbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ impl<T, const CAP: usize> StaticThingBuf<T, CAP> {
/// 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())
}
Expand All @@ -217,6 +218,7 @@ impl<T, const CAP: usize, R> StaticThingBuf<T, CAP, R> {
/// the provided [recycling policy].
///
/// [recycling policy]: crate::recycling::Recycle
#[must_use]
pub const fn with_recycle(recycle: R) -> Self {
StaticThingBuf {
core: Core::new(CAP),
Expand Down
2 changes: 2 additions & 0 deletions src/thingbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ pub struct ThingBuf<T, R = recycling::DefaultRecycle> {

impl<T: Default + Clone> ThingBuf<T> {
/// Returns a new `ThingBuf` with space for `capacity` elements.
#[must_use]
pub fn new(capacity: usize) -> Self {
Self::with_recycle(capacity, recycling::DefaultRecycle::new())
}
Expand Down Expand Up @@ -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 {
Expand Down