This commit is contained in:
Numbers
2025-05-29 03:45:41 +02:00
commit ebf6bde22d
10 changed files with 654 additions and 0 deletions

33
src/streams.rs Normal file
View File

@@ -0,0 +1,33 @@
use crate::{MalformedData, Reader, Writer};
impl Reader for &[u8] {
#[inline(always)]
fn read(&mut self, bytes: &mut [u8]) -> e::Result<()> {
if bytes.len() > self.len() { Err(MalformedData)? }
unsafe {
core::ptr::copy_nonoverlapping(
self.as_ptr(),
bytes.as_mut_ptr(),
bytes.len()
)
}
*self = &self[bytes.len()..];
Ok(())
}
#[inline(always)]
fn remainder_hint(&self) -> usize {
self.len()
}
}
#[cfg(feature = "alloc")]
impl Writer for alloc::vec::Vec<u8> {
fn write(&mut self, bytes: &[u8]) -> e::Result<()> {
self.extend_from_slice(bytes);
Ok(())
}
}