macro_rules! impl_function_constant_method {
($struct_name:ident < $t:ident, $r:ident >, $($extra_bounds:tt)+) => {
impl<$t, $r> $struct_name<$t, $r> {
#[doc = concat!("/// ```ignore\n/// use qubit_function as qf;\n/// use qf::{", stringify!($struct_name), ", Function};\n///\n/// let constant = ", stringify!($struct_name), "::constant(\"hello\");\n/// assert_eq!(constant.apply(123), \"hello\");\n/// ```")]
#[inline]
pub fn constant(value: $r) -> $struct_name<$t, $r>
where
$r: Clone + $($extra_bounds)+,
{
$struct_name::new(move |_: &$t| value.clone())
}
}
};
($struct_name:ident < $t:ident, $u:ident, $r:ident >) => {
impl<$t, $u, $r> $struct_name<$t, $u, $r> {
#[doc = concat!("/// ```ignore\n/// use qubit_function as qf;\n/// use qf::{", stringify!($struct_name), ", BiFunction};\n///\n/// let constant = ", stringify!($struct_name), "::constant(\"hello\");\n/// assert_eq!(constant.apply(123, \"test\"), \"hello\");\n/// ```")]
#[inline]
pub fn constant(value: $r) -> $struct_name<$t, $u, $r>
where
$r: Clone + 'static,
{
$struct_name::new(move |_: &$t, _: &$u| value.clone())
}
}
};
($struct_name:ident < $t:ident, $u:ident, $r:ident >, mut $($extra_bounds:tt)+) => {
impl<$t, $u, $r> $struct_name<$t, $u, $r> {
#[inline]
pub fn constant(value: $r) -> $struct_name<$t, $u, $r>
where
$r: Clone + $($extra_bounds)+,
{
$struct_name::new(move |_: &mut $t, _: &mut $u| value.clone())
}
}
};
($struct_name:ident < $t:ident, $u:ident, $r:ident >, $($extra_bounds:tt)+) => {
impl<$t, $u, $r> $struct_name<$t, $u, $r> {
#[doc = concat!("/// ```ignore\n/// use qubit_function as qf;\n/// use qf::{", stringify!($struct_name), ", BiFunction};\n///\n/// let constant = ", stringify!($struct_name), "::constant(\"hello\");\n/// assert_eq!(constant.apply(123, \"test\"), \"hello\");\n/// ```")]
#[inline]
pub fn constant(value: $r) -> $struct_name<$t, $u, $r>
where
$r: Clone + $($extra_bounds)+,
{
$struct_name::new(move |_: &$t, _: &$u| value.clone())
}
}
};
}
pub(crate) use impl_function_constant_method;