Skip to content

Commit

Permalink
Rollup merge of #137353 - thaliaarchi:io-optional-methods/wasi-stdin,…
Browse files Browse the repository at this point in the history
… r=alexcrichton

Implement `read_buf` for WASI stdin

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

cc `@alexcrichton`

Tracked in #136756
  • Loading branch information
matthiaskrgr authored Feb 21, 2025
2 parents a24eb0b + d32eeb8 commit ef14e9a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion library/std/src/sys/pal/wasi/stdio.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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)
}
Expand Down Expand Up @@ -64,6 +68,7 @@ impl io::Write for Stdout {
fn is_write_vectored(&self) -> bool {
true
}

fn flush(&mut self) -> io::Result<()> {
Ok(())
}
Expand Down

0 comments on commit ef14e9a

Please sign in to comment.