Not sure if this has been mentioned before, but I’ve currently got a lot of code like the following:
fn my_func() -> Result<Obj, MyError> {
let file = File::open("some/path")
.context(ErrorReadingConfig)?
.read_to_end()
.context(ErrorReadingConfig)?;
let mut d = Deserializer::from_bytes(&file);
let val = T::deserialize(&mut d)
.context(ErrorReadingConfig)?;
d.end()
.context(ErrorReadingConfig)?;
Ok(val)
}
Maybe it would be nice to be able to do the following:
fn my_func() -> Result<Obj, MyError> {
try {
let file = File::open("some/path")?
.read_to_end()?;
let mut d = Deserializer::from_bytes(&file);
let val = T::deserialize(&mut d)?;
d.end()?;
val
}.with_context(ErrorReadingConfig)
}
but I don’t know if that’s too much magic.
Was wondering what the current thinking from the powers that be is?