Hi all!
Thank you for your time; I promise I’ve done my best to find the answer to this question on my own.
I’m trying to write a super simple function to return an iterator over a buffer.
fn read_file<'a>(filename: String) -> Chars<'a> {
let file = File::open(filename).expect("failed to open file");
let mut reader = BufReader::new(file);
let mut buf = String::new();
reader.read_to_string(&mut buf);
buf.chars()
}
I realize that the problem is that my string buf
is stack allocated and needs a lifetime of 'a
. However, I have no idea how to make this happen. I’ve tried things like boxing my iterator, boxing my string, and calling clone. However, I’m obviously missing something fundamental. I’ve read RustByExample and the Rust book, and I’m reading Programming Rust (Blandy and Orendorff).
Thank you for your time and attention. I appreciate the help!