1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
//! This module contains the macros
//! for creating new participants.
//!
//! *This module is available only if MultiCrusty is built with
//! the `"macros_simple"` feature.*
/// Create a new [`Name`].
///
/// # Arguments
///
/// * The name of the new [`Name`]
///
/// # Example
///
/// ```
/// use mpstthree::create_normal_name;
///
/// // Create the name *A*
/// create_normal_name!(A);
/// ```
///
/// [`Name`]: crate::name::Name
///
/// *This macro is available only if MultiCrusty is built with
/// the `"macros_simple"` feature.*
#[macro_export]
#[cfg_attr(doc_cfg, doc(cfg(feature = "macros_simple")))]
macro_rules! create_normal_name {
($name:ident) => {
////////////////////////////////////////////
/// The Name
#[derive(Debug)]
pub struct $name {
#[doc(hidden)]
sender: crossbeam_channel::Sender<()>,
#[doc(hidden)]
receiver: crossbeam_channel::Receiver<()>,
}
////////////////////////////////////////////
/// The Name functions
impl mpstthree::name::Name for $name {
type Dual = $name;
#[doc(hidden)]
fn new() -> (Self, Self::Dual) {
let (sender1, receiver1) = crossbeam_channel::bounded::<()>(1);
let (sender2, receiver2) = crossbeam_channel::bounded::<()>(1);
(
$name {
sender: sender1,
receiver: receiver2,
},
$name {
sender: sender2,
receiver: receiver1,
},
)
}
#[doc(hidden)]
fn head_str() -> String {
String::from(stringify!($name))
}
#[doc(hidden)]
fn tail_str() -> String {
"".to_string()
}
#[doc(hidden)]
fn self_head_str(&self) -> String {
String::from(stringify!($name))
}
#[doc(hidden)]
fn self_tail_str(&self) -> String {
"".to_string()
}
}
};
}
/// Create multiple new [`Name`].
///
/// # Arguments
///
/// * The name of the new [`Name`]
///
/// # Example
///
/// ```
/// use mpstthree::create_multiple_normal_name;
///
/// // Create the names *A* and *B*
/// create_multiple_normal_name!(A, B);
/// ```
///
/// [`Name`]: crate::name::Name
///
/// *This macro is available only if MultiCrusty is built with
/// the `"macros_simple"` feature.*
#[macro_export]
#[cfg_attr(doc_cfg, doc(cfg(feature = "macros_simple")))]
macro_rules! create_multiple_normal_name {
($( $name: ident),+ $(,)? ) => {
$(mpstthree::create_normal_name!($name);)+
}
}
///////////////////////////////
/// Create a new [`Name`].
/// When a name *X* is given, the Names created are
///
/// * NameX
/// * NameXDual
///
/// If you want to specify other names, please use [`create_normal_name`].
///
/// # Arguments
///
/// * The name of the new [`Name`]
///
/// # Example
///
/// ```
/// use mpstthree::create_normal_name_short;
///
/// // Create the names *NameA* and *NameADual*
/// create_normal_name_short!(A);
/// ```
///
/// [`Name`]: crate::name::Name
/// [`create_normal_name`]: crate::create_normal_name
///
/// *This macro is available only if MultiCrusty is built with
/// the `"macros_simple"` feature.*
#[macro_export]
#[cfg_attr(doc_cfg, doc(cfg(feature = "macros_simple")))]
macro_rules! create_normal_name_short {
($name:ident) => {
mpst_seq_proc::create_normal_name_short!($name);
};
}
/// Create multiple new [`Name`].
/// When a name *X* is given, the Names created are
///
/// * NameX
/// * NameXDual
///
/// If you want to specify other names, please use [`create_multiple_normal_name`].
///
/// # Arguments
///
/// * The names of the new [`Name`]
///
/// # Example
///
/// ```
/// use mpstthree::create_multiple_normal_name_short;
///
/// // Create the names *NameA*, *NameB*, *NameC*,
/// // *NameADual*, *NameBDual* and *NameCDual*
/// create_multiple_normal_name_short!(A, B, C);
/// ```
///
/// [`Name`]: crate::name::Name
/// [`create_multiple_normal_name`]: crate::create_multiple_normal_name
///
/// *This macro is available only if MultiCrusty is built with
/// the `"macros_simple"` feature.*
#[macro_export]
#[cfg_attr(doc_cfg, doc(cfg(feature = "macros_simple")))]
macro_rules! create_multiple_normal_name_short {
($( $name: ident),+ $(,)? ) => {
$(
mpstthree::create_normal_name_short!($name);
)+
}
}