4 ms·
Haskell could have (I don't know a library that implements this, but it's ~trivial) do x <- open filename `errorContext` ("failed to open " <> filena
by lalaithion 4y ago
Haskell could have (I don't know a library that implements this, but it's ~trivial)
do
x <- open filename `errorContext` ("failed to open " <> filename)
y <- readBytes x `errorContext` "failed to read bytes from file"
Rust has
let x = open(filename).with_context(|| format!("failed to open {}", filename)?;
let y = read_bytes(x).with_context(|| format!("failed to read bytes from file")?;
or if we ever get https://github.com/joshtriplett/rfcs/blob/simple-postfix-macros/text/2442-simple-postfix-macros.md https://github.com/joshtriplett/rfcs/blob/simple-postfix-mac...,
let x = open(filename).with_context!("failed to open {}", filename)?;
let y = read_bytes(x).with_context!("failed to read bytes from file")?;