I would like to set a generic value (n) in the array based on the bytes that are written in the stream. Now I do not know the exact length of the buffer, I just create a hard coded array to read the stream bytes.
use mio::net::TcpStream;
...
let mut buf = [0;12];
stream.read_exact(&mut buf).unwrap();
I would like to swap the 12 hard coded length for a bytes length (n), any clues?
Use
Read::read_to_end(). It won't work with non-blocking streams, but just usetokio. Example of usingtokio'sread_to_end():