Skip to main content

devela/work/sync/mpsc/
namespace.rs

1// devela::sys::work::sync::mpsc::namespace
2//
3//! Defines the [`Mpsc`] namespace.
4//
5
6#[cfg(feature = "std")]
7use crate::{MpscReceiver, MpscSender, MpscSyncSender};
8#[cfg(feature = "std")]
9use std::sync::mpsc::{channel, sync_channel};
10
11#[doc = crate::_tags!(concurrency namespace)]
12/// Multi-producer, single-consumer channel operations.
13#[doc = crate::_doc_meta!{location("work/sync/mpsc")}]
14#[derive(Debug)]
15pub struct Mpsc;
16
17#[cfg(feature = "std")]
18#[cfg_attr(nightly_doc, doc(cfg(feature = "std")))]
19impl Mpsc {
20    /// Creates a new asynchronous channel, returning the sender/receiver halves.
21    ///
22    /// See `std::sync::mpsc::`[`channel`].
23    #[must_use]
24    pub fn channel<T>() -> (MpscSender<T>, MpscReceiver<T>) {
25        channel()
26    }
27
28    /// Creates a new synchronous, bounded channel.
29    ///
30    /// See `std::sync::mpsc::`[`sync_channel`].
31    #[must_use]
32    pub fn sync_channel<T>(bound: usize) -> (MpscSyncSender<T>, MpscReceiver<T>) {
33        sync_channel(bound)
34    }
35}