Xudong-Huang / generator-rs

rust stackful generator library
Apache License 2.0
286 stars 35 forks source link

(probably) erroneous warning #22

Closed robinmoussu closed 3 years ago

robinmoussu commented 3 years ago

When some of the values generated by a generator created by Gn are not consumed, a warning appears in the logs.

I assumed this warning is erroneous, and should at most be a trace!() if any.

use generator::*;

// This generator seems totally fine
fn generate_values(start: u8) -> impl Iterator<Item = u8> {
    Gn::new_scoped(move |mut s| { // The warning will only appears if it's a moved closure
        for i in start..20 {
            s.yield_(i);
        }
        done!()
    })
}

fn main() {
    env_logger::init();
    let _: Vec<_> = dbg!(
        generate_values(3).
        .take(3) // this will abort the generator early
        .collect());
}
# Cargo.toml
[dependencies]
log = "0.4"
env_logger = "0.7.1"
$ RUST_LOG=trace cargo run
[2020-07-24T15:45:33Z WARN  generator::gen_impl] generator is not done while drop
[src/main.rs:26] foo(3).take(3).collect() = [
    3,
    4,
    5,
]
Xudong-Huang commented 3 years ago

Make sense. I will update it in next release.

robinmoussu commented 3 years ago

@Xudong-Huang I think you forgot to modify this in 0.6.22.

Xudong-Huang commented 3 years ago

released in 0.6.23