Created
November 27, 2021 02:31
-
-
Save roneygomes/c7e93061af9575774a8e3ed3672880e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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