Skip to content

Commit

Permalink
eq_ref
Browse files Browse the repository at this point in the history
  • Loading branch information
MingweiSamuel committed Jun 28, 2024
1 parent 3996a76 commit 301545f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions variadics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ impl CloneRefVariadic for () {
pub trait PartialEqVariadic: Variadic {
/// `PartialEq` between a referenced variadic and a variadic of references, of the same types.
fn eq(&self, other: &Self) -> bool;

/// `PartialEq` for the `AsRefVar` version op `Self`.
fn eq_ref<'a>(this: Self::AsRefVar<'a>, other: Self::AsRefVar<'a>) -> bool
where
Self: VariadicExt;
}
#[sealed]
impl<Item, Rest> PartialEqVariadic for (Item, Rest)
Expand All @@ -363,12 +368,34 @@ where
let var_args!(item_other, ...rest_other) = other;
item_self == item_other && rest_self.eq(rest_other)
}

fn eq_ref<'a>(
this: <Self as VariadicExt>::AsRefVar<'a>,
other: <Self as VariadicExt>::AsRefVar<'a>,
) -> bool
where
Self: VariadicExt,
{
let var_args!(item_self, ...rest_self) = this;
let var_args!(item_other, ...rest_other) = other;
item_self == item_other && rest_self.eq(rest_other)
}
}
#[sealed]
impl PartialEqVariadic for () {
fn eq(&self, _other: &Self) -> bool {
true
}

fn eq_ref<'a>(
_this: <Self as VariadicExt>::AsRefVar<'a>,
_other: <Self as VariadicExt>::AsRefVar<'a>,
) -> bool
where
Self: VariadicExt,
{
true
}
}

/// A variadic where all elements are the same type, `T`.
Expand Down

0 comments on commit 301545f

Please sign in to comment.