How to read (std::io::Read) from a Vec or Slice?

While vectors don’t support std::io::Read, slices do. There is some confusion here caused by Rust being able to coerce a Vec into a slice in some situations but not others. In this case, an explicit coercion to a slice is needed because at the stage coercions are applied, the compiler doesn’t know that Vec<u8> doesn’t … Read more

The best way to get a string from a Writer

If your function accepts an io.Writer, you can pass a *bytes.Buffer to capture the output. // import “bytes” buf := new(bytes.Buffer) f(buf) buf.String() // returns a string of what was written to it If it requires an http.ResponseWriter, you can use a *httptest.ResponseRecorder. A response recorder holds all information that can be sent to a … Read more

Can anyone explain precisely what IOWait is?

I know it’s the time spent by the CPU waiting for a IO operations to complete, but what kind of IO operations precisely? What I am also not sure, is why it so important? Can’t the CPU just do something else while the IO operation completes, and then get back to processing data? Yes, the … Read more