I didn't read the other post and haven't tried to figure out what you're trying to do enough to suggest a solution, but I can explain the error.
Here is the Fields
trait and the GAT parts of the implementations. I simplified the bounds of the implementations, but with no change in meaning.
pub trait Fields<K, V> {
type Key<'k> where Self: 'k;
type Val<'v> where Self: 'v;
fn fields(&self) -> impl IteratorTrait<Item = (Self::Key<'_>, Self::Val<'_>)>;
}
impl<V> Fields<usize, &'_ V> for Vec<V> where V: std::borrow::ToOwned {
type Key<'k> = usize where Self: 'k;
type Val<'v> = &'v V where Self: 'v;
}
impl<K, V> Fields<&'_ K, &'_ V> for HashMap<K, V>
where
K: core::hash::Hash + core::cmp::Eq,
V: std::borrow::ToOwned,
{
type Key<'k> = &'k K where Self: 'k;
type Val<'v> = &'v V where Self: 'v;
}
And here's the bound that's involved in the error.
impl<T, RowKey, Row> TableRows for AsTable<'_, T, RowKey, Row>
where
for<'k, 'v> T: Fields<
RowKey,
&'k Row,
Key<'k> = RowKey,
Val<'v> = &'v Row
> + 'k + 'v,
RowKey: crate::RowKey,
Type parameters like RowKey
resolve to a single type, which means that to meet this part of the bound:
T: for<'k> Fields<_, _, Key<'k> = RowKey>
the actual type of Key<'k>
can't involve 'k
-- because that would be a different type for every lifetime 'k
.
// This bound can be met: let RowKey = usize
Vec<V>: for<'k> Fields<_, _, Key<'k> = RowKey>
// This bound *cannot* be met, because for every distinct
// lifetime `'k`, `&'k K` is a distinct type
HashMap<K, V>: for<'k> Fields<_, _, Key<'k> = RowKey>
Or perhaps another way to think about it: RowKey
can't resolve to &'k K
because RowKey
exists outside of the for<'k> ...
bound, where 'k
isn't defined.