macro_rules! impl_transformer_constant_method {
($struct_name:ident < $t:ident, $r:ident >) => {
impl<$t, $r> $struct_name<$t, $r> {
#[doc = concat!("/// ```rust\n/// use qubit_function::{", stringify!($struct_name), ", Transformer};\n///\n/// let constant = ", stringify!($struct_name), "::constant(\"hello\");\n/// assert_eq!(constant.apply(123), \"hello\");\n/// ```")]
pub fn constant(value: $r) -> $struct_name<$t, $r>
where
$r: Clone + 'static,
{
$struct_name::new(move |_| value.clone())
}
}
};
(thread_safe $struct_name:ident < $t:ident, $r:ident >) => {
impl<$t, $r> $struct_name<$t, $r> {
#[doc = concat!("/// ```rust\n/// use qubit_function::{", stringify!($struct_name), ", Transformer};\n///\n/// let constant = ", stringify!($struct_name), "::constant(\"hello\");\n/// assert_eq!(constant.apply(123), \"hello\");\n/// ```")]
pub fn constant(value: $r) -> $struct_name<$t, $r>
where
$r: Clone + Send + Sync + 'static,
{
$struct_name::new(move |_| value.clone())
}
}
};
($struct_name:ident < $t:ident, $u:ident, $r:ident >) => {
impl<$t, $u, $r> $struct_name<$t, $u, $r> {
#[doc = concat!("/// ```rust\n/// use qubit_function::{", stringify!($struct_name), ", BiTransformer};\n///\n/// let constant = ", stringify!($struct_name), "::constant(\"hello\");\n/// assert_eq!(constant.apply(123, 456), \"hello\");\n/// ```")]
pub fn constant(value: $r) -> $struct_name<$t, $u, $r>
where
$r: Clone + 'static,
{
$struct_name::new(move |_, _| value.clone())
}
}
};
(thread_safe $struct_name:ident < $t:ident, $u:ident, $r:ident >) => {
impl<$t, $u, $r> $struct_name<$t, $u, $r> {
#[doc = concat!("/// ```rust\n/// use qubit_function::{", stringify!($struct_name), ", BiTransformer};\n///\n/// let constant = ", stringify!($struct_name), "::constant(\"hello\");\n/// assert_eq!(constant.apply(123, 456), \"hello\");\n/// ```")]
pub fn constant(value: $r) -> $struct_name<$t, $u, $r>
where
$r: Clone + Send + Sync + 'static,
{
$struct_name::new(move |_, _| value.clone())
}
}
};
(stateful $struct_name:ident < $t:ident, $r:ident >) => {
impl<$t, $r> $struct_name<$t, $r> {
#[doc = concat!("/// ```rust\n/// use qubit_function::{", stringify!($struct_name), ", StatefulTransformer};\n///\n/// let mut constant = ", stringify!($struct_name), "::constant(\"hello\");\n/// assert_eq!(constant.apply(123), \"hello\");\n/// ```")]
pub fn constant(value: $r) -> $struct_name<$t, $r>
where
$r: Clone + 'static,
{
$struct_name::new(move |_| value.clone())
}
}
};
(stateful thread_safe $struct_name:ident < $t:ident, $r:ident >) => {
impl<$t, $r> $struct_name<$t, $r> {
#[doc = concat!("/// ```rust\n/// use qubit_function::{", stringify!($struct_name), ", StatefulTransformer};\n///\n/// let mut constant = ", stringify!($struct_name), "::constant(\"hello\");\n/// assert_eq!(constant.apply(123), \"hello\");\n/// ```")]
pub fn constant(value: $r) -> $struct_name<$t, $r>
where
$r: Clone + Send + 'static,
{
$struct_name::new(move |_| value.clone())
}
}
};
(stateful $struct_name:ident < $t:ident, $u:ident, $r:ident >) => {
impl<$t, $u, $r> $struct_name<$t, $u, $r> {
#[doc = concat!("/// ```rust\n/// use qubit_function::{", stringify!($struct_name), ", StatefulBiTransformer};\n///\n/// let constant = ", stringify!($struct_name), "::constant(\"hello\");\n/// assert_eq!(constant.apply(123, 456), \"hello\");\n/// ```")]
pub fn constant(value: $r) -> $struct_name<$t, $u, $r>
where
$r: Clone + 'static,
{
$struct_name::new(move |_, _| value.clone())
}
}
};
(stateful thread_safe $struct_name:ident < $t:ident, $u:ident, $r:ident >) => {
impl<$t, $u, $r> $struct_name<$t, $u, $r> {
#[doc = concat!("/// ```rust\n/// use qubit_function::{", stringify!($struct_name), ", StatefulBiTransformer};\n///\n/// let constant = ", stringify!($struct_name), "::constant(\"hello\");\n/// assert_eq!(constant.apply(123, 456), \"hello\");\n/// ```")]
pub fn constant(value: $r) -> $struct_name<$t, $u, $r>
where
$r: Clone + Send + 'static,
{
$struct_name::new(move |_, _| value.clone())
}
}
};
}
pub(crate) use impl_transformer_constant_method;