News for hackers. Stuff that matters.
Re:Fast Rust Builds by capableweb on Sunday September 05, 2021 @02:07PM (#28426344)
I don't know Rust but converting that code snippet of Go code you wrote to (non-idiomatic [wouldn't use upper-case characters, namespaces used doesn't actually exists]) Clojure:

    (defn Read [path]
      (io/ReadToEnd (os/Open path)))
Now that's what I call readable!
Re:Fast Rust Builds by scottlamb on Sunday September 05, 2021 @04:14PM (#28427376)
You can chain calls in Rust. If read_to_end were written to allocate and return a fresh Vec, you could do this:

    File::open(path)?.read_to_end()
but instead read_to_end is written to take a presupplied Vec so the caller has the option to reduce allocations.
Re:Fast Rust Builds by masklinn on Monday September 06, 2021 @11:18AM (#28434531)
> Now that's what I call readable!

Unsurprisingly APIs can be more readable when you don't ponder why they're designed the way they are and completely ignore their purpose.

The `read_to_end` API[0] was designed such that the buffer could be reused in order to avoid unnecessary allocations.

There are helpers for common tasks, though people may not know or notice them. In the case of `Read::read_to_end`, it's called std::fs::read[1], which actually preallocates the vector based on file size internally so might be faster than hand-rolling `read_to_end`.

So here's your code in Rust, for the last 3 years or so (since 1.26 was released):

    fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
        std::fs::read(path)
    }
[0] and all of the Read trait in general

[1] https://doc.rust-lang.org/std/fs/fn.read.html

Re:Fast Rust Builds by brundolf on Sunday September 05, 2021 @02:52PM (#28426715)
Clojure is also a much higher-level language than Rust (and arguably Go too)