so, I wanted to read the contents of a file. i wanted use the result and not just panic if something went wrong, ie not expect. this was my first attempt:
let r = File::open("a.txt").and_then(|f| {
let mut s = String::new();
f.read_to_string(&mut s).and_then(|_| Ok(s))
});
this told me I couldn't borrow f as mutable. aha! I next tried:
let r = File::open("a.txt").as_mut().and_then(|f| {
let mut s = String::new();
f.read_to_string(&mut s).as_mut().and_then(|_| Ok(s))
});
I now get borrowed value does not live long enough. At this point I believe I'm stuck, or is this even possible?
The .as_mut() isn't enough, because it's called on a value that hasn't been assigned to a variable, so it lives only temporarily for the expression (one line)