error[E0597]: `lowercase` does not live long enough
--> src\lib.rs:37:23
|
37 | iterator: lowercase.chars().peekable(),
| ^^^^^^^^^ borrowed value does not live long enough
38 | }
39 | }
| - borrowed value only lives until here
|
note: borrowed value must be valid for the lifetime 'a as defined on the impl at 33:6...
--> src\lib.rs:33:6
|
33 | impl<'a> TokenIterator<'a> {
| ^^
I understand the cause for the issue, but I can't figure out how I should rewrite the code to make it work. Maybe, redesign is required?
The point is: I want to pass a string to this custom iterator, so that it then contains an iterator over lowercase chars of given string, so that I later can enumerate over it in actual iterator implementation.
I think I like @jonh's solution more, as the interface is more straightforward to use, and also it is close to my original struct, even though it looks so cryptic for me on current level of Rust understanding. If I were to write the same code from scratch, I couldn't write it . I yet have to learn how to read and understand this code.