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

add Iterable traits #7597

Closed
thestinger opened this issue Jul 5, 2013 · 7 comments
Closed

add Iterable traits #7597

thestinger opened this issue Jul 5, 2013 · 7 comments
Labels
A-trait-system Area: Trait system C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@thestinger
Copy link
Contributor

Something like the following:

trait Iterable<'self, A, T: Iterator<&'self A>> {
    fn iter(&'self self) -> T;
}

trait ReverseIterable<'self, A, T: Iterator<&'self A>> {
    fn rev_iter(&'self self) -> T;
}

trait MutableIterable<'self, A, T: Iterator<&'self mut A>> {
    fn mut_iter(&'self mut self) -> T;
}

trait MutableReverseIterable<'self, A, T: Iterator<&'self mut A>> {
    fn mut_rev_iter(&'self mut self) -> T;
}

In the future we can define default methods like enumerate when method resolve is fixed. #5898

@thestinger
Copy link
Contributor Author

This is not yet possible due to issues (including ICEs) related to lifetimes. At least some are already reported, but I'll look into this more.

@bluss
Copy link
Member

bluss commented Jul 27, 2013

This version of Iterable does not apply to str since it iterates by value, nor hashmap since it iterates by (&'self Key, &'self Value).

@thestinger
Copy link
Contributor Author

@blake2-ppc: yup, but it gets really problematic if you omit the &'self A and use A instead - rustc just isn't capable of compiling it yet

@catamorphism
Copy link
Contributor

Triage bump.

@aturon
Copy link
Member

aturon commented May 21, 2014

See also erickt's RFC proposing a somewhat similar design with additional convenience methods.

@japaric
Copy link
Member

japaric commented Oct 13, 2014

I think this should be closed (or moved to rust-lang/rfcs) since it requires an accepted RFC to be implemented, and there are two RFCs that address this issue: rust-lang/rfcs#17 (Iterable) and rust-lang/rfcs#235 (Collection reform).

@rust-highfive
Copy link
Collaborator

This issue has been moved to the RFCs repo: rust-lang/rfcs#397

flip1995 pushed a commit to flip1995/rust that referenced this issue Apr 21, 2022
assertions_on_constants: ignore indirect `cfg!`

Fixes rust-lang#7597

changelog: [`assertions_on_constants`] ignore constants indirectly based on `cfg!`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

6 participants