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.
Trait Implementations§
source§impl<W: Write + Any + Send + Sync> WasiFile for WritePipe<W>
impl<W: Write + Any + Send + Sync> WasiFile for WritePipe<W>
fn as_any(&self) -> &dyn Any
fn get_filetype<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<FileType, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_fdflags<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<FdFlags, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn write_vectored<'a, 'life0, 'life1, 'async_trait>(
&'life0 self,
bufs: &'life1 [IoSlice<'a>],
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn pollable(&self) -> Option<BorrowedFd<'_>>
fn isatty(&self) -> bool
fn sock_accept<'life0, 'async_trait>(
&'life0 self,
_fdflags: FdFlags,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn WasiFile>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn sock_recv<'a, 'life0, 'life1, 'async_trait>(
&'life0 self,
_ri_data: &'life1 mut [IoSliceMut<'a>],
_ri_flags: RiFlags,
) -> Pin<Box<dyn Future<Output = Result<(u64, RoFlags), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn sock_send<'a, 'life0, 'life1, 'async_trait>(
&'life0 self,
_si_data: &'life1 [IoSlice<'a>],
_si_flags: SiFlags,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn sock_shutdown<'life0, 'async_trait>(
&'life0 self,
_how: SdFlags,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn datasync<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn sync<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set_fdflags<'life0, 'async_trait>(
&'life0 mut self,
_flags: FdFlags,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_filestat<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Filestat, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set_filestat_size<'life0, 'async_trait>(
&'life0 self,
_size: u64,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn advise<'life0, 'async_trait>(
&'life0 self,
_offset: u64,
_len: u64,
_advice: Advice,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set_times<'life0, 'async_trait>(
&'life0 self,
_atime: Option<SystemTimeSpec>,
_mtime: Option<SystemTimeSpec>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn read_vectored<'a, 'life0, 'life1, 'async_trait>(
&'life0 self,
_bufs: &'life1 mut [IoSliceMut<'a>],
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn read_vectored_at<'a, 'life0, 'life1, 'async_trait>(
&'life0 self,
_bufs: &'life1 mut [IoSliceMut<'a>],
_offset: u64,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn write_vectored_at<'a, 'life0, 'life1, 'async_trait>(
&'life0 self,
_bufs: &'life1 [IoSlice<'a>],
_offset: u64,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn seek<'life0, 'async_trait>(
&'life0 self,
_pos: SeekFrom,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn peek<'life0, 'life1, 'async_trait>(
&'life0 self,
_buf: &'life1 mut [u8],
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn num_ready_bytes(&self) -> Result<u64, Error>
fn readable<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn writable<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Auto Trait Implementations§
impl<W> Freeze for WritePipe<W>
impl<W> RefUnwindSafe for WritePipe<W>
impl<W> Send for WritePipe<W>
impl<W> Sync for WritePipe<W>
impl<W> Unpin for WritePipe<W>
impl<W> UnwindSafe for WritePipe<W>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
Query the “status” flags for the
self
file descriptor.§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more