Skip to content

Make an Iterable trait to make it quicker for a programmer to iterate over something #524

@Kilobyte22

Description

@Kilobyte22

Currently when we want to iterate over an Array we always have to call .iter() on that array. I suggest that there should be a trait to standardize this:

pub trait Iterable<T> {
  fn iter(&self) -> Iterator<T>;
}

Now, rustc would check in for loops for instances of Iterable and automatically adding a .iter(). This would allow for code like this:

let a = ["a", "b", "c"];
for element in a {
  println!("Element: {}", element);
}

The old way would obviously still work, this would only be syntactic sugar

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions