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 a trait for external iterator objects #5599

Closed
thestinger opened this issue Mar 28, 2013 · 1 comment
Closed

add a trait for external iterator objects #5599

thestinger opened this issue Mar 28, 2013 · 1 comment

Comments

@thestinger
Copy link
Contributor

There's currently an example of this in the treemap module, since it's required to set methods like intersection in-order. An external iterator is basically a state machine, so they're somewhat painful to write by hand but it's possible to generate them automatically, and that could be tackled at some point (probably post-1.0).

The only method the trait will require is fn next(&mut self) -> Option<T>. A default implementation a wrapper (see {map, set}_advance in treemap.rs) for integrating with for loops can be provided.

Unlike internal iteration that works with a closure, external iterators can be interleaved and keep their state when you break out of a loop. All iterators (forward, reverse, range within a container, counter, etc.) can implement the same interface, which means a generic library like Python's itertools can be written around them.

Blocking on #5598 for now, because this should be done with methods.

@ghost ghost assigned thestinger Mar 28, 2013
@thestinger
Copy link
Contributor Author

Fixed by 7158102.

@thestinger thestinger removed their assignment Jun 16, 2014
flip1995 pushed a commit to flip1995/rust that referenced this issue May 17, 2020
Downgrade useless_let_if_seq to nursery

I feel that this lint has the wrong balance of incorrect suggestions for a default-enabled lint.

The immediate code I faced was something like:

```rust
fn main() {
    let mut good = do1();
    if !do2() {
        good = false;
    }
    if good {
        println!("good");
    }
}

fn do1() -> bool { println!("1"); false }
fn do2() -> bool { println!("2"); false }
```

On this code Clippy calls it unidiomatic and suggests the following diff, which has different behavior in a way that I don't necessarily want.

```diff
- let mut good = do1();
- if !do2() {
-     good = false;
- }
+ let good = if !do2() {
+     false
+ } else {
+     do1()
+ };
```

On exploring issues filed about this lint, I have found that other users have also struggled with inappropriate suggestions (rust-lang/rust-clippy#4124, rust-lang/rust-clippy#3043, rust-lang/rust-clippy#2918, rust-lang/rust-clippy#2176) and suggestions that make the code worse (rust-lang/rust-clippy#3769, rust-lang/rust-clippy#2749). Overall I believe that this lint is still at nursery quality for now and should not be enabled.

---

changelog: Remove useless_let_if_seq from default set of enabled lints
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