Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions crates/iddqd/src/bi_hash_map/trait_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,51 @@ pub trait BiHashItem {
) -> Self::K2<'short>;
}

impl<A, B> BiHashItem for (A, B)
where
A: Eq + Hash,
B: Eq + Hash,
{
type K1<'a>
= &'a A
where
A: 'a,
B: 'a;
type K2<'a>
= &'a B
where
A: 'a,
B: 'a;

fn key1(&self) -> Self::K1<'_> {
&self.0
}

fn key2(&self) -> Self::K2<'_> {
&self.1
}

fn upcast_key1<'short, 'long: 'short>(
long: Self::K1<'long>,
) -> Self::K1<'short>
where
A: 'long,
B: 'long,
{
long
}

fn upcast_key2<'short, 'long: 'short>(
long: Self::K2<'long>,
) -> Self::K2<'short>
where
A: 'long,
B: 'long,
{
long
}
}

macro_rules! impl_for_ref {
($type:ty) => {
impl<'b, T: 'b + ?Sized + BiHashItem> BiHashItem for $type {
Expand Down
71 changes: 71 additions & 0 deletions crates/iddqd/src/tri_hash_map/trait_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,77 @@ pub trait TriHashItem {
) -> Self::K3<'short>;
}

impl<A, B, C> TriHashItem for (A, B, C)
where
A: Eq + Hash,
B: Eq + Hash,
C: Eq + Hash,
{
type K1<'a>
= &'a A
where
A: 'a,
B: 'a,
C: 'a;
type K2<'a>
= &'a B
where
A: 'a,
B: 'a,
C: 'a;
type K3<'a>
= &'a C
where
A: 'a,
B: 'a,
C: 'a;

fn key1(&self) -> Self::K1<'_> {
&self.0
}

fn key2(&self) -> Self::K2<'_> {
&self.1
}

fn key3(&self) -> Self::K3<'_> {
&self.2
}

fn upcast_key1<'short, 'long: 'short>(
long: Self::K1<'long>,
) -> Self::K1<'short>
where
A: 'long,
B: 'long,
C: 'long,
{
long
}

fn upcast_key2<'short, 'long: 'short>(
long: Self::K2<'long>,
) -> Self::K2<'short>
where
A: 'long,
B: 'long,
C: 'long,
{
long
}

fn upcast_key3<'short, 'long: 'short>(
long: Self::K3<'long>,
) -> Self::K3<'short>
where
A: 'long,
B: 'long,
C: 'long,
{
long
}
}

macro_rules! impl_for_ref {
($type:ty) => {
impl<'b, T: 'b + ?Sized + TriHashItem> TriHashItem for $type {
Expand Down
Loading