mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Implement read_buf for WASI stdin
This commit is contained in:
parent
f04bbc60f8
commit
d32eeb86b2
@ -1,7 +1,7 @@
|
||||
#![forbid(unsafe_op_in_unsafe_fn)]
|
||||
|
||||
use super::fd::WasiFd;
|
||||
use crate::io::{self, IoSlice, IoSliceMut};
|
||||
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut};
|
||||
use crate::mem::ManuallyDrop;
|
||||
use crate::os::raw;
|
||||
use crate::os::wasi::io::{AsRawFd, FromRawFd};
|
||||
@ -28,6 +28,10 @@ impl io::Read for Stdin {
|
||||
self.read_vectored(&mut [IoSliceMut::new(data)])
|
||||
}
|
||||
|
||||
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> {
|
||||
ManuallyDrop::new(unsafe { WasiFd::from_raw_fd(self.as_raw_fd()) }).read_buf(buf)
|
||||
}
|
||||
|
||||
fn read_vectored(&mut self, data: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
|
||||
ManuallyDrop::new(unsafe { WasiFd::from_raw_fd(self.as_raw_fd()) }).read(data)
|
||||
}
|
||||
@ -64,6 +68,7 @@ impl io::Write for Stdout {
|
||||
fn is_write_vectored(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user