I'm trying to generate a sequence like this: 1,2,3,4,5,6,7,8,9,1,0,1,1,1,2...
fn main() {
let iter = (1..).flat_map(|j| j.to_string().chars());
for i in iter {
println!("{}", i);
}
}
This does not work, because j.to_string()
goes out of scope I believe (but why?)
p040.rs:2:35: 2:48 error: borrowed value does not live long enough
p040.rs:2 let iter = (1..).flat_map(|j| j.to_string().chars());
^~~~~~~~~~~~~
p040.rs:2:58: 6:2 note: reference must be valid for the block suffix following statement 0 at 2:57...
p040.rs:2 let iter = (1..).flat_map(|j| j.to_string().chars());
p040.rs:3 for i in iter {
p040.rs:4 println!("{}", i);
p040.rs:5 }
p040.rs:6 }
p040.rs:2:35: 2:56 note: ...but borrowed value is only valid for the block at 2:34
p040.rs:2 let iter = (1..).flat_map(|j| j.to_string().chars());
^~~~~~~~~~~~~~~~~~~~~
How could I solve this compiler error?