1- use std:: mem:: ManuallyDrop ;
1+ use std:: { io , mem:: ManuallyDrop } ;
22
3- use crate :: pipe:: { Receiver , Sender } ;
43use compio_buf:: { BufResult , IoBuf , IoBufMut } ;
5- use compio_driver:: AsRawFd ;
4+ use compio_driver:: { AsRawFd , FromRawFd , RawFd } ;
65use compio_io:: { AsyncRead , AsyncWrite } ;
7- use compio_runtime:: FromRawFd ;
6+ use compio_runtime:: TryAsRawFd ;
7+
8+ use crate :: pipe:: { Receiver , Sender } ;
89
910/// A handle to the standard input stream of a process.
1011///
@@ -14,7 +15,7 @@ pub struct Stdin(ManuallyDrop<Receiver>);
1415impl Stdin {
1516 pub ( crate ) fn new ( ) -> Self {
1617 Self ( ManuallyDrop :: new ( unsafe {
17- Receiver :: from_raw_fd ( std :: io:: stdin ( ) . as_raw_fd ( ) )
18+ Receiver :: from_raw_fd ( io:: stdin ( ) . as_raw_fd ( ) )
1819 } ) )
1920 }
2021}
@@ -25,6 +26,16 @@ impl AsyncRead for Stdin {
2526 }
2627}
2728
29+ impl TryAsRawFd for Stdin {
30+ fn try_as_raw_fd ( & self ) -> io:: Result < RawFd > {
31+ self . 0 . try_as_raw_fd ( )
32+ }
33+
34+ unsafe fn as_raw_fd_unchecked ( & self ) -> RawFd {
35+ self . 0 . as_raw_fd_unchecked ( )
36+ }
37+ }
38+
2839/// A handle to the standard output stream of a process.
2940///
3041/// See [`stdout`].
@@ -33,7 +44,7 @@ pub struct Stdout(ManuallyDrop<Sender>);
3344impl Stdout {
3445 pub ( crate ) fn new ( ) -> Self {
3546 Self ( ManuallyDrop :: new ( unsafe {
36- Sender :: from_raw_fd ( std :: io:: stdout ( ) . as_raw_fd ( ) )
47+ Sender :: from_raw_fd ( io:: stdout ( ) . as_raw_fd ( ) )
3748 } ) )
3849 }
3950}
@@ -43,15 +54,25 @@ impl AsyncWrite for Stdout {
4354 self . 0 . write ( buf) . await
4455 }
4556
46- async fn flush ( & mut self ) -> std :: io:: Result < ( ) > {
57+ async fn flush ( & mut self ) -> io:: Result < ( ) > {
4758 self . 0 . flush ( ) . await
4859 }
4960
50- async fn shutdown ( & mut self ) -> std :: io:: Result < ( ) > {
61+ async fn shutdown ( & mut self ) -> io:: Result < ( ) > {
5162 self . 0 . shutdown ( ) . await
5263 }
5364}
5465
66+ impl TryAsRawFd for Stdout {
67+ fn try_as_raw_fd ( & self ) -> io:: Result < RawFd > {
68+ self . 0 . try_as_raw_fd ( )
69+ }
70+
71+ unsafe fn as_raw_fd_unchecked ( & self ) -> RawFd {
72+ self . 0 . as_raw_fd_unchecked ( )
73+ }
74+ }
75+
5576/// A handle to the standard output stream of a process.
5677///
5778/// See [`stderr`].
@@ -60,7 +81,7 @@ pub struct Stderr(ManuallyDrop<Sender>);
6081impl Stderr {
6182 pub ( crate ) fn new ( ) -> Self {
6283 Self ( ManuallyDrop :: new ( unsafe {
63- Sender :: from_raw_fd ( std :: io:: stderr ( ) . as_raw_fd ( ) )
84+ Sender :: from_raw_fd ( io:: stderr ( ) . as_raw_fd ( ) )
6485 } ) )
6586 }
6687}
@@ -70,11 +91,21 @@ impl AsyncWrite for Stderr {
7091 self . 0 . write ( buf) . await
7192 }
7293
73- async fn flush ( & mut self ) -> std :: io:: Result < ( ) > {
94+ async fn flush ( & mut self ) -> io:: Result < ( ) > {
7495 self . 0 . flush ( ) . await
7596 }
7697
77- async fn shutdown ( & mut self ) -> std :: io:: Result < ( ) > {
98+ async fn shutdown ( & mut self ) -> io:: Result < ( ) > {
7899 self . 0 . shutdown ( ) . await
79100 }
80101}
102+
103+ impl TryAsRawFd for Stderr {
104+ fn try_as_raw_fd ( & self ) -> io:: Result < RawFd > {
105+ self . 0 . try_as_raw_fd ( )
106+ }
107+
108+ unsafe fn as_raw_fd_unchecked ( & self ) -> RawFd {
109+ self . 0 . as_raw_fd_unchecked ( )
110+ }
111+ }
0 commit comments