Skip to content

Instantly share code, notes, and snippets.

@Akanoa
Created April 13, 2024 11:14
Show Gist options
  • Save Akanoa/80e69ead6f2dafa5e5ed370ecab72068 to your computer and use it in GitHub Desktop.
Save Akanoa/80e69ead6f2dafa5e5ed370ecab72068 to your computer and use it in GitHub Desktop.
const buffer
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