init
This commit is contained in:
33
src/streams.rs
Normal file
33
src/streams.rs
Normal 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(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user