4 ms·
Here's the cleaned up version of Rust from the OP: pub fn read(path: Path) -> Bytes { let file = File::open(path); let bytes = Bytes::new(); file
by librasteve 2y ago
Here's the cleaned up version of Rust from the OP:
pub fn read(path: Path) -> Bytes {
let file = File::open(path);
let bytes = Bytes::new();
file.read_to_end(bytes);
bytes
}
Here is is in raku (https://raku.org https://raku.org):
sub read(Str:D $path --> Buf:D) {
$path.IO.slurp: :bin
}
[the `--> Buf:D` is the raku alternative to monads]
- sedatk 2y agoThen it’s just this with C#: public byte[] Read(string path) => File.ReadAllBytes(path); I think the article’s trying to explain a concept using an arbitrary piece of code from stdlib, not necessarily that specific scenario (opening and reading all bytes from a file).
- neonsunset 2y agoThis. In general, standard library is a poor example as it has to serve very wide range of scenarios, be robust to many environmental conditions when IO is involved and perform optimally. If it's terse enough while doing so, it's good enough already.
- librasteve 2y agowell no need for the sub wrapper really say $path.IO.slurp: :bin