1 use crate::io::{self, IoSlice, IoSliceMut};
2 use crate::mem::ManuallyDrop;
3 use crate::sys::fd::WasiFd;
10 pub fn new() -> io::Result<Stdin> {
15 pub fn as_raw_fd(&self) -> u32 {
20 impl io::Read for Stdin {
21 fn read(&mut self, data: &mut [u8]) -> io::Result<usize> {
22 self.read_vectored(&mut [IoSliceMut::new(data)])
25 fn read_vectored(&mut self, data: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
26 ManuallyDrop::new(unsafe { WasiFd::from_raw(self.as_raw_fd()) }).read(data)
30 fn is_read_vectored(&self) -> bool {
36 pub fn new() -> io::Result<Stdout> {
41 pub fn as_raw_fd(&self) -> u32 {
46 impl io::Write for Stdout {
47 fn write(&mut self, data: &[u8]) -> io::Result<usize> {
48 self.write_vectored(&[IoSlice::new(data)])
51 fn write_vectored(&mut self, data: &[IoSlice<'_>]) -> io::Result<usize> {
52 ManuallyDrop::new(unsafe { WasiFd::from_raw(self.as_raw_fd()) }).write(data)
56 fn is_write_vectored(&self) -> bool {
59 fn flush(&mut self) -> io::Result<()> {
65 pub fn new() -> io::Result<Stderr> {
70 pub fn as_raw_fd(&self) -> u32 {
75 impl io::Write for Stderr {
76 fn write(&mut self, data: &[u8]) -> io::Result<usize> {
77 self.write_vectored(&[IoSlice::new(data)])
80 fn write_vectored(&mut self, data: &[IoSlice<'_>]) -> io::Result<usize> {
81 ManuallyDrop::new(unsafe { WasiFd::from_raw(self.as_raw_fd()) }).write(data)
85 fn is_write_vectored(&self) -> bool {
89 fn flush(&mut self) -> io::Result<()> {
94 pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
96 pub fn is_ebadf(err: &io::Error) -> bool {
97 err.raw_os_error() == Some(wasi::ERRNO_BADF.into())
100 pub fn panic_output() -> Option<impl io::Write> {