Created
April 13, 2024 11:14
-
-
Save Akanoa/80e69ead6f2dafa5e5ed370ecab72068 to your computer and use it in GitHub Desktop.
const buffer
This file contains hidden or 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
struct Buffer<const N: usize> { | |
data: [u8; N] | |
} | |
impl<const N: usize> Buffer<N> { | |
fn new() -> Self { | |
Self { | |
data: [0; N] | |
} | |
} | |
} | |
impl<const N: usize> Read for Buffer<N> { | |
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> { | |
buf.copy_from_slice(&self.data[0..N]); | |
Ok(N) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment