Skip to content

Be consistent about where Self: Sized bounds on &mut self methods #44

@taylordotfish

Description

@taylordotfish

Certain &mut self methods of Iterator have a where Self: Sized bound, like try_fold and position. At first, this bound doesn't seem necessary, but as I understand it, this is necessary to make the trait dyn-compatible.

The issue is that only some of the equivalent methods in LendingIterator have the same where Self: Sized bound. In particular, try_fold, try_for_each, and try_find do have it, but all, any, find, find_map, and position don't, even though the equivalent Iterator methods do.

Because traits with GATs cannot be dyn-compatible anyway, one option would be to remove the bound from try_fold, try_for_each, and try_find (and try_reduce if #45 is fixed). However, it is possible that the dyn compatibility restriction on GATs could be lifted in the future, and perhaps it is intended for LendingIterator to become dyn compatible once that restriction is lifted. In that case, the bound should be added to the other methods.

One of the motivations for this is #34. There are many methods that could have a more efficient implementation if it weren't for the mismatched bounds—for example, all could be written in terms of try_for_each if the two methods either both had a Self: Sized bound or both didn't have one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions