Skip to content

Instantly share code, notes, and snippets.

@roneygomes
Created November 27, 2021 02:31
Show Gist options
  • Save roneygomes/c7e93061af9575774a8e3ed3672880e1 to your computer and use it in GitHub Desktop.
Save roneygomes/c7e93061af9575774a8e3ed3672880e1 to your computer and use it in GitHub Desktop.
use std::io::Write;
use std::io::Result;
#[derive(Debug)]
struct ArrayWrapper {
pub buffer: Vec<u8>,
}
impl Write for ArrayWrapper {
fn write(&mut self, buf: &[u8]) -> Result<usize> {
for byte in buf {
self.buffer.push(byte.clone())
}
Ok(buf.len())
}
fn flush(&mut self) -> Result<()> {
Ok(())
}
}
fn main() {
let bytes = vec![128, 255, 144];
let mut array_wrapper = ArrayWrapper {
buffer: vec![]
};
let _ = array_wrapper.write(&bytes);
println!("{:?}", array_wrapper);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment