pub(super) fn write_to_buf(self: Pin<&mut Self>, buf: &[u8]) -> usize {
        let available = self.spare_capacity();
        let amt_to_buffer = available.min(buf.len());

        // SAFETY: `amt_to_buffer` is <= buffer's spare capacity by construction.
        unsafe {
            self.write_to_buffer_unchecked(&buf[..amt_to_buffer]);
        }

        amt_to_buffer
    }
Write a byte slice directly into buffer

Will truncate the number of bytes written to `spare_capacity()` so you want to
calculate the size of your slice to avoid losing bytes

Based on `std::io::BufWriter`
futures-util/src/io/buf_writer.rs