diff --git a/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs b/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs index 9210914a182c..daee20335ed8 100644 --- a/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs +++ b/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs @@ -336,6 +336,20 @@ pub struct DirectDestination<'a, D: 'static> { store: StoreContextMut<'a, D>, } +impl std::io::Write for DirectDestination<'_, D> { + fn write(&mut self, buf: &[u8]) -> std::io::Result { + 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 DirectDestination<'_, D> { /// Provide direct access to the writer's buffer. pub fn remaining(&mut self) -> &mut [u8] { @@ -836,6 +850,16 @@ pub struct DirectSource<'a, D: 'static> { store: StoreContextMut<'a, D>, } +impl std::io::Read for DirectSource<'_, D> { + fn read(&mut self, buf: &mut [u8]) -> std::io::Result { + 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 DirectSource<'_, D> { /// Provide direct access to the writer's buffer. pub fn remaining(&mut self) -> &[u8] {