Function in Ascent's Relation Read/Write Traits should return iterator type or iterator's impl trait? #78
StarGazerM
started this conversation in
General
Replies: 1 comment
-
|
I agree that it is painful to have to write the type name, and I've thought about using RPITIT (return position impl trait in trait) instead, but I think the better solution long-term is For now, you can use a nightly compiler, and enable this feature to avoid having to spell out the type name: #![feature(impl_trait_in_assoc_type)]
use ascent::internal::RelIndexRead;
use std::collections::BTreeMap;
struct TestRelIndex<K, V>(BTreeMap<K, Vec<V>>);
impl<'a, K: 'a, V: 'a> RelIndexReadAll<'a> for TestRelIndex<K, V>
where
K: Eq + Ord,
{
type Key = &'a K;
type Value = &'a V;
type ValueIteratorType = impl Iterator<Item = Self::Value> + 'a;
type AllIteratorType = impl Iterator<Item = (Self::Key, Self::ValueIteratorType)> + 'a;
fn iter_all(&'a self) -> Self::AllIteratorType {
self.0.iter().map(|(k, vs)| (k, vs.iter()))
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Now trait like
RelIndexReadAllneed explicitly declare the returned iterator type. Can we return a impl of Iterator instead? come up with correct iterator type is painful, return impl should have the same function but much simpler code?(commented are original code in Ascent)
Beta Was this translation helpful? Give feedback.
All reactions