diff options
| author | bors <bors@rust-lang.org> | 2022-10-04 23:22:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-10-04 23:22:16 +0000 |
| commit | d4846f9d03659704af1f6b56bb4278bf843a4627 (patch) | |
| tree | 235475992d9bc5848314c33788e11d3e68f84e14 | |
| parent | 01af5040fdada6ef8f1b749cda798d80a8590b2c (diff) | |
| parent | 905ebc31b1514d3d7f2a7043d437c82253727455 (diff) | |
| download | rust-d4846f9d03659704af1f6b56bb4278bf843a4627.tar.gz rust-d4846f9d03659704af1f6b56bb4278bf843a4627.zip | |
Auto merge of #101768 - sunfishcode:sunfishcode/wasi-stdio-lock-asfd, r=joshtriplett
Add `AsFd` implementations for stdio lock types on WASI. This mirrors the implementations on Unix platforms, and also mirrors the existing `AsRawFd` impls. This is similar to #100892, but is for the `*Lock` types.
| -rw-r--r-- | library/std/src/sys/wasi/stdio.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/library/std/src/sys/wasi/stdio.rs b/library/std/src/sys/wasi/stdio.rs index d2081771b6e..bf045c7841f 100644 --- a/library/std/src/sys/wasi/stdio.rs +++ b/library/std/src/sys/wasi/stdio.rs @@ -30,6 +30,15 @@ impl AsFd for Stdin { } } +#[stable(feature = "io_safety", since = "1.63.0")] +impl<'a> AsFd for io::StdinLock<'a> { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + // SAFETY: user code should not close stdin out from under the standard library + unsafe { BorrowedFd::borrow_raw(0) } + } +} + impl io::Read for Stdin { fn read(&mut self, data: &mut [u8]) -> io::Result<usize> { self.read_vectored(&mut [IoSliceMut::new(data)]) @@ -65,6 +74,15 @@ impl AsFd for Stdout { } } +#[stable(feature = "io_safety", since = "1.63.0")] +impl<'a> AsFd for io::StdoutLock<'a> { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + // SAFETY: user code should not close stdout out from under the standard library + unsafe { BorrowedFd::borrow_raw(1) } + } +} + impl io::Write for Stdout { fn write(&mut self, data: &[u8]) -> io::Result<usize> { self.write_vectored(&[IoSlice::new(data)]) @@ -103,6 +121,15 @@ impl AsFd for Stderr { } } +#[stable(feature = "io_safety", since = "1.63.0")] +impl<'a> AsFd for io::StderrLock<'a> { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + // SAFETY: user code should not close stderr out from under the standard library + unsafe { BorrowedFd::borrow_raw(2) } + } +} + impl io::Write for Stderr { fn write(&mut self, data: &[u8]) -> io::Result<usize> { self.write_vectored(&[IoSlice::new(data)]) |
