1
Fork 0

Rollup merge of #137353 - thaliaarchi:io-optional-methods/wasi-stdin, r=alexcrichton

Implement `read_buf` for WASI stdin

`WasiFd::read_buf` already exists. Simply use it in `Stdin`.

cc `@alexcrichton`

Tracked in https://github.com/rust-lang/rust/issues/136756
This commit is contained in:
Matthias Krüger 2025-02-21 19:01:15 +01:00 committed by GitHub
commit ef14e9a6d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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(())
}