#[macro_export]
macro_rules! default_impl {
(
$ty:ident
// Accept generics
< T $(, $gen:ident $(: $gen_bound:path)?)* $(,)?>
$(
where
$(
$extra_bound_ty:ident: $extra_bound:path
),+
)?
) => {
impl<T: Default + 'static
$(, $gen $(: $gen_bound)?)*
> Default for $ty <T $(, $gen)*>
$(
where
$(
$extra_bound_ty: $extra_bound
),+
)?
{
#[track_caller]
fn default() -> Self {
Self::new_maybe_sync(Default::default())
}
}
}
}
#[macro_export]
macro_rules! read_impls {
(
$ty:ident
// Accept generics
< T $(, $gen:ident $(: $gen_bound:path)?)* $(,)?>
$(
where
$(
$extra_bound_ty:ident: $extra_bound:path
),+
)?
) => {
$crate::fmt_impls!{
$ty<
T
$(
, $gen
$(: $gen_bound)?
)*
>
$(
where
$($extra_bound_ty: $extra_bound),*
)?
}
$crate::eq_impls!{
$ty<
T
$(
, $gen
$(: $gen_bound)?
)*
>
$(
where
$($extra_bound_ty: $extra_bound),*
)?
}
};
}
#[macro_export]
macro_rules! fmt_impls {
(
$ty:ident
// Accept generics
< T $(, $gen:ident $(: $gen_bound:path)?)* $(,)?>
$(
where
$(
$extra_bound_ty:ident: $extra_bound:path
),+
)?
) => {
impl<
T: std::fmt::Display + 'static
$(, $gen $(: $gen_bound)?)*
> std::fmt::Display for $ty<T $(, $gen)*>
$(
where
$($extra_bound_ty: $extra_bound,)*
)?
{
#[track_caller]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.with(|v| std::fmt::Display::fmt(v, f))
}
}
impl<
T: std::fmt::Debug + 'static
$(, $gen $(: $gen_bound)?)*
> std::fmt::Debug for $ty<T $(, $gen)*>
$(
where
$($extra_bound_ty: $extra_bound,)*
)?
{
#[track_caller]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.with(|v| std::fmt::Debug::fmt(v, f))
}
}
};
}
#[macro_export]
macro_rules! eq_impls {
(
$ty:ident
// Accept generics
< T $(, $gen:ident $(: $gen_bound:path)?)* $(,)?>
$(
where
$(
$extra_bound_ty:ident: $extra_bound:path
),+
)?
) => {
impl<
T: PartialEq + 'static
$(, $gen $(: $gen_bound)?)*
> PartialEq<T> for $ty<T $(, $gen)*>
$(
where
$($extra_bound_ty: $extra_bound,)*
)?
{
#[track_caller]
fn eq(&self, other: &T) -> bool {
self.with(|v| *v == *other)
}
}
};
}
#[macro_export]
macro_rules! write_impls {
(
$ty:ident
// Accept generics
< T $(, $gen:ident $(: $gen_bound:path)?)* $(,)?>
$(
where
$(
$extra_bound_ty:ident: $extra_bound:path
),+
)?) => {
impl<T: std::ops::Add<Output = T> + Copy + 'static
$(, $gen $(: $gen_bound)?)*
> std::ops::Add<T>
for $ty<T $(, $gen)*>
$(
where
$($extra_bound_ty: $extra_bound,)*
)?
{
type Output = T;
#[track_caller]
fn add(self, rhs: T) -> Self::Output {
self.with(|v| *v + rhs)
}
}
impl<T: std::ops::Add<Output = T> + Copy + 'static
$(, $gen $(: $gen_bound)?)*
> std::ops::AddAssign<T>
for $ty<T $(, $gen)*>
$(
where
$($extra_bound_ty: $extra_bound,)*
)?
{
#[track_caller]
fn add_assign(&mut self, rhs: T) {
self.with_mut(|v| *v = *v + rhs)
}
}
impl<T: std::ops::Sub<Output = T> + Copy + 'static
$(, $gen $(: $gen_bound)?)*
> std::ops::SubAssign<T>
for $ty<T $(, $gen)*>
$(
where
$($extra_bound_ty: $extra_bound,)*
)?
{
#[track_caller]
fn sub_assign(&mut self, rhs: T) {
self.with_mut(|v| *v = *v - rhs)
}
}
impl<T: std::ops::Sub<Output = T> + Copy + 'static
$(, $gen $(: $gen_bound)?)*
> std::ops::Sub<T>
for $ty<T $(, $gen)*>
$(
where
$($extra_bound_ty: $extra_bound,)*
)?
{
type Output = T;
#[track_caller]
fn sub(self, rhs: T) -> Self::Output {
self.with(|v| *v - rhs)
}
}
impl<T: std::ops::Mul<Output = T> + Copy + 'static
$(, $gen $(: $gen_bound)?)*
> std::ops::MulAssign<T>
for $ty<T $(, $gen)*>
$(
where
$($extra_bound_ty: $extra_bound,)*
)?
{
#[track_caller]
fn mul_assign(&mut self, rhs: T) {
self.with_mut(|v| *v = *v * rhs)
}
}
impl<T: std::ops::Mul<Output = T> + Copy + 'static
$(, $gen $(: $gen_bound)?)*
> std::ops::Mul<T>
for $ty<T $(, $gen)*>
$(
where
$($extra_bound_ty: $extra_bound,)*
)?
{
type Output = T;
#[track_caller]
fn mul(self, rhs: T) -> Self::Output {
self.with(|v| *v * rhs)
}
}
impl<T: std::ops::Div<Output = T> + Copy + 'static
$(, $gen $(: $gen_bound)?)*
> std::ops::DivAssign<T>
for $ty<T $(, $gen)*>
$(
where
$($extra_bound_ty: $extra_bound,)*
)?
{
#[track_caller]
fn div_assign(&mut self, rhs: T) {
self.with_mut(|v| *v = *v / rhs)
}
}
impl<T: std::ops::Div<Output = T> + Copy + 'static
$(, $gen $(: $gen_bound)?)*
> std::ops::Div<T>
for $ty<T $(, $gen)*>
$(
where
$($extra_bound_ty: $extra_bound,)*
)?
{
type Output = T;
#[track_caller]
fn div(self, rhs: T) -> Self::Output {
self.with(|v| *v / rhs)
}
}
};
}