Struct wasi_common::pipe::WritePipe
source · pub struct WritePipe<W: Write> { /* private fields */ }
Expand description
A virtual pipe write end.
use wasi_common::{pipe::WritePipe, WasiCtx, Table};
let stdout = WritePipe::new_in_memory();
// Brint these instances from elsewhere (e.g. wasi-cap-std-sync):
let random = todo!();
let clocks = todo!();
let sched = todo!();
let table = Table::new();
let mut ctx = WasiCtx::new(random, clocks, sched, table);
ctx.set_stdout(Box::new(stdout.clone()));
// use ctx in an instance, then make sure it is dropped:
drop(ctx);
let contents: Vec<u8> = stdout.try_into_inner().expect("sole remaining reference to WritePipe").into_inner();
println!("contents of stdout: {:?}", contents);
Implementations§
source§impl<W: Write> WritePipe<W>
impl<W: Write> WritePipe<W>
sourcepub fn new(w: W) -> Self
pub fn new(w: W) -> Self
Create a new pipe from a Write
type.
All Handle
write operations delegate to writing to this underlying writer.
Create a new pipe from a shareable Write
type.
All Handle
write operations delegate to writing to this underlying writer.
sourcepub fn try_into_inner(self) -> Result<W, Self>
pub fn try_into_inner(self) -> Result<W, Self>
Try to convert this WritePipe<W>
back to the underlying W
type.
This will fail with Err(self)
if multiple references to the underlying W
exist.