I have the following function to parse mail in Rust.
fn read_mail(fname: &Path) -> Result<mailparse::ParsedMail, mailparse::MailParseError> {
let mut f = File::open(fname).unwrap();
let mut buf = String::new();
let _ = f.read_to_string(&mut buf);
mailparse::parse_mail(buf.as_bytes())
}
Here buf
only lives until the function returns and parse_mail
borrows it. This won't compile since the return value would outlive it's borrow.
How can I tell Rust that buf
can have a longer lifetime until the return value is destroyed?