#How can I push data into my buffer?
10 messages · Page 1 of 1 (latest)
I have a buffer of the same type and I want to push all of it's content into the global_buffer
if you want to use an array then you have to keep track of where in the array you have to write
since it's an array of u8, https://doc.rust-lang.org/std/io/struct.Cursor.html can do that for you
A Cursor wraps an in-memory buffer and provides it with a [Seek] implementation.
which will then allow you to write bytes into it
How can I implement that?
The local buffer:
let mut buffer = [0; 10000];
let n = stream.read(&mut buffer[..]).unwrap();
make the buffer a Cursor<[u8; 10000]>
then write into it using std::io::Write
or if you want to do the direct copy, use https://doc.rust-lang.org/std/io/struct.Cursor.html#method.position to find out where you should start your slice for read()
or if you actually want to copy the entire input then use https://doc.rust-lang.org/std/io/fn.copy.html
Copies the entire contents of a reader into a writer.