1 #![deny(unsafe_op_in_unsafe_fn)]
4 use crate::io::{self, IoSlice, IoSliceMut};
5 use crate::mem::ManuallyDrop;
12 pub const fn new() -> Stdin {
17 pub fn as_raw_fd(&self) -> u32 {
22 impl io::Read for Stdin {
23 fn read(&mut self, data: &mut [u8]) -> io::Result<usize> {
24 self.read_vectored(&mut [IoSliceMut::new(data)])
27 fn read_vectored(&mut self, data: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
28 ManuallyDrop::new(unsafe { WasiFd::from_raw(self.as_raw_fd()) }).read(data)
32 fn is_read_vectored(&self) -> bool {
38 pub const fn new() -> Stdout {
43 pub fn as_raw_fd(&self) -> u32 {
48 impl io::Write for Stdout {
49 fn write(&mut self, data: &[u8]) -> io::Result<usize> {
50 self.write_vectored(&[IoSlice::new(data)])
53 fn write_vectored(&mut self, data: &[IoSlice<'_>]) -> io::Result<usize> {
54 ManuallyDrop::new(unsafe { WasiFd::from_raw(self.as_raw_fd()) }).write(data)
58 fn is_write_vectored(&self) -> bool {
61 fn flush(&mut self) -> io::Result<()> {
67 pub const fn new() -> Stderr {
72 pub fn as_raw_fd(&self) -> u32 {
77 impl io::Write for Stderr {
78 fn write(&mut self, data: &[u8]) -> io::Result<usize> {
79 self.write_vectored(&[IoSlice::new(data)])
82 fn write_vectored(&mut self, data: &[IoSlice<'_>]) -> io::Result<usize> {
83 ManuallyDrop::new(unsafe { WasiFd::from_raw(self.as_raw_fd()) }).write(data)
87 fn is_write_vectored(&self) -> bool {
91 fn flush(&mut self) -> io::Result<()> {
96 pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
98 pub fn is_ebadf(err: &io::Error) -> bool {
99 err.raw_os_error() == Some(wasi::ERRNO_BADF.into())
102 pub fn panic_output() -> Option<impl io::Write> {