use std::any::Any;
use wasi_common::file::{FdFlags, FileType};
use wasi_common::{Error, WasiFile};
pub struct Null;
#[wiggle::async_trait]
impl WasiFile for Null {
fn as_any(&self) -> &dyn Any {
self
}
async fn get_filetype(&mut self) -> Result<FileType, Error> {
Ok(FileType::Pipe)
}
async fn get_fdflags(&mut self) -> Result<FdFlags, Error> {
Ok(FdFlags::APPEND | FdFlags::NONBLOCK)
}
async fn read_vectored<'a>(
&mut self,
_bufs: &mut [std::io::IoSliceMut<'a>],
) -> Result<u64, Error> {
Ok(0)
}
async fn read_vectored_at<'a>(
&mut self,
_bufs: &mut [std::io::IoSliceMut<'a>],
_offset: u64,
) -> Result<u64, Error> {
Ok(0)
}
async fn write_vectored<'a>(&mut self, bufs: &[std::io::IoSlice<'a>]) -> Result<u64, Error> {
Ok(bufs.iter().map(|b| b.len()).sum::<usize>() as _)
}
async fn write_vectored_at<'a>(
&mut self,
bufs: &[std::io::IoSlice<'a>],
_offset: u64,
) -> Result<u64, Error> {
Ok(bufs.iter().map(|b| b.len()).sum::<usize>() as _)
}
async fn peek(&mut self, _buf: &mut [u8]) -> Result<u64, Error> {
Ok(0)
}
async fn readable(&self) -> Result<(), Error> {
Ok(())
}
async fn writable(&self) -> Result<(), Error> {
Ok(())
}
}