5 ms·
Why stop there and not go all the way to pub fn read(path: Path) -> Bytes { File::open(path).read_to_end() }
by remcob 2y ago
Why stop there and not go all the way to
pub fn read(path: Path) -> Bytes {
File::open(path).read_to_end()
}
- oneshtein 2y agoHow to return an error in your example?
- tcfhgj 2y agoThrow an exception proving the point of the article even further
- gary_0 2y agopub fn read(path: Path) -> Result<Bytes> { File::open(path)?.read_to_end() } isn't so bad either.
- remcob 2y agoExactly, and this is in my experience what most Rust code ends up looking like. It compromises a bit on generality and (potential) performance to achieve better readability and succinctness. Often a worthwhile trade-off, but not something the standard library can always do.