about summary refs log tree commit diff
path: root/library/std/src/sys/pal
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2025-02-21 19:01:15 +0100
committerGitHub <noreply@github.com>2025-02-21 19:01:15 +0100
commitef14e9a6d0feabf4757fec0a3c0b3a7c64c36d09 (patch)
treebbb8aa61eeb97ab680a2ad089a26ca5c588e4024 /library/std/src/sys/pal
parenta24eb0bae9b51df19a26c5241cabc3ebc008bd38 (diff)
parentd32eeb86b2f3e8e08ea40da6e374e754ed790cb4 (diff)
downloadrust-ef14e9a6d0feabf4757fec0a3c0b3a7c64c36d09.tar.gz
rust-ef14e9a6d0feabf4757fec0a3c0b3a7c64c36d09.zip
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
Diffstat (limited to 'library/std/src/sys/pal')
-rw-r--r--library/std/src/sys/pal/wasi/stdio.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/library/std/src/sys/pal/wasi/stdio.rs b/library/std/src/sys/pal/wasi/stdio.rs
index d08b772e5fc..fb21cb4d393 100644
--- a/library/std/src/sys/pal/wasi/stdio.rs
+++ b/library/std/src/sys/pal/wasi/stdio.rs
@@ -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(())
     }