Skip to content

Instantly share code, notes, and snippets.

@roneygomes
Created November 27, 2021 02:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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