Struct wasi_common::pipe::ReadPipe
source · pub struct ReadPipe<R: Read> { /* private fields */ }
Expand description
A virtual pipe read end.
A variety of From
impls are provided so that common pipe types are easy to create. For example:
use wasi_common::{pipe::ReadPipe, WasiCtx, Table};
let stdin = ReadPipe::from("hello from stdin!");
// 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_stdin(Box::new(stdin.clone()));
Implementations§
source§impl<R: Read> ReadPipe<R>
impl<R: Read> ReadPipe<R>
sourcepub fn new(r: R) -> Self
pub fn new(r: R) -> Self
Create a new pipe from a Read
type.
All Handle
read operations delegate to reading from this underlying reader.
Examples found in repository?
src/pipe.rs (line 81)
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
fn from(r: Vec<u8>) -> Self {
Self::new(io::Cursor::new(r))
}
}
impl From<&[u8]> for ReadPipe<io::Cursor<Vec<u8>>> {
fn from(r: &[u8]) -> Self {
Self::from(r.to_vec())
}
}
impl From<String> for ReadPipe<io::Cursor<String>> {
fn from(r: String) -> Self {
Self::new(io::Cursor::new(r))
}
More examples
src/ctx.rs (line 35)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
pub fn new(
random: Box<dyn RngCore + Send + Sync>,
clocks: WasiClocks,
sched: Box<dyn WasiSched>,
table: Table,
) -> Self {
let mut s = WasiCtx {
args: StringArray::new(),
env: StringArray::new(),
random,
clocks,
sched,
table,
};
s.set_stdin(Box::new(crate::pipe::ReadPipe::new(std::io::empty())));
s.set_stdout(Box::new(crate::pipe::WritePipe::new(std::io::sink())));
s.set_stderr(Box::new(crate::pipe::WritePipe::new(std::io::sink())));
s
}
Create a new pipe from a shareable Read
type.
All Handle
read operations delegate to reading from this underlying reader.
sourcepub fn try_into_inner(self) -> Result<R, Self>
pub fn try_into_inner(self) -> Result<R, Self>
Try to convert this ReadPipe<R>
back to the underlying R
type.
This will fail with Err(self)
if multiple references to the underlying R
exist.