Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,20 @@ pub struct DirectDestination<'a, D: 'static> {
store: StoreContextMut<'a, D>,
}

impl<D: 'static> std::io::Write for DirectDestination<'_, D> {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
let rem = self.remaining();
let n = rem.len().min(buf.len());
rem[..n].copy_from_slice(&buf[..n]);
self.mark_written(n);
Ok(n)
}

fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
}

impl<D: 'static> DirectDestination<'_, D> {
/// Provide direct access to the writer's buffer.
pub fn remaining(&mut self) -> &mut [u8] {
Expand Down Expand Up @@ -836,6 +850,16 @@ pub struct DirectSource<'a, D: 'static> {
store: StoreContextMut<'a, D>,
}

impl<D: 'static> std::io::Read for DirectSource<'_, D> {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
let rem = self.remaining();
let n = rem.len().min(buf.len());
buf[..n].copy_from_slice(&rem[..n]);
self.mark_read(n);
Ok(n)
}
}

impl<D: 'static> DirectSource<'_, D> {
/// Provide direct access to the writer's buffer.
pub fn remaining(&mut self) -> &[u8] {
Expand Down