Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntoParallelRefIterator and IntoParallelRefMutIterator are overly constrained #90

Closed
cuviper opened this issue Sep 6, 2016 · 0 comments

Comments

@cuviper
Copy link
Member

cuviper commented Sep 6, 2016

I was trying some implementations for #88 std collections (WIP), but I hit a stumbling block on IntoParallelRefIterator and IntoParallelRefMutIterator. These both require their Item to be the type behind the reference, so the ParallelIterator's Item is this &Item and &mut Item respectively. That's OK for most collections, but the map iterators use (&K, &V) and (&K, &mut V).

It would be nicer if the Item represented the same as the parallel iterator, so both the typical &T and map's (&K, &V) can work. Perhaps some future collection would even like something that only emulates a reference, like a cell Ref or a MutexGuard.

With this made more general, it can also have a blanket implementation, like:

pub trait IntoParallelRefIterator<'data> {
    type Iter: ParallelIterator<Item=Self::Item>;
    type Item: Send + 'data;

    fn par_iter(&'data self) -> Self::Iter;
}

impl<'data, T: 'data + ?Sized> IntoParallelRefIterator<'data> for T
    where &'data T: IntoParallelIterator
{
    type Iter = <&'data T as IntoParallelIterator>::Iter;
    type Item = <&'data T as IntoParallelIterator>::Item;

    fn par_iter(&'data self) -> Self::Iter {
        self.into_par_iter()
    }
}

Users of this trait would now lose the ability to assume that par_iter() yields simple references, but I'm not sure that's actually needed or valuable.

Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant