We love Result because it is explicit, right? You can see all of the places where your function can fail, marked right there in the source code, and you can see how all of the errors are handled. All in perfect alignment with the virtues of Rust.
Except… allow me to pose a rhetorical question.
The following is the full body of a function.
How many of the function calls in it can fail?
{
let prim = poscar::read(File::open("PPOSCAR")?)?;
let prim_ops = read_symmetry("sym.yaml")?;
let factor = lattice_divide(structure.lattice(), prim.lattice())?;
supercell_ops(&structure, &prim_ops, &factor)
}
In case my rhetoric is lost...
The function contains 4 places where results are explicitly handled/forwarded, but there are actually five places where it can fail.
I don’t know about you, but I’ve begun writing my Result<...> function bodies as
{Ok({
...body here...
})}
Not only does it fix the issue of explicitness above; but it also gets rid of that pesky Ok(()). 