@@ -4,7 +4,7 @@ use super::fd::WasiFd;
4
4
use crate :: io:: { self , IoSlice , IoSliceMut } ;
5
5
use crate :: mem:: ManuallyDrop ;
6
6
use crate :: os:: raw;
7
- use crate :: os:: wasi:: io:: { AsRawFd , FromRawFd } ;
7
+ use crate :: os:: wasi:: io:: { AsFd , AsRawFd , BorrowedFd , FromRawFd } ;
8
8
9
9
pub struct Stdin ;
10
10
pub struct Stdout ;
@@ -23,6 +23,13 @@ impl AsRawFd for Stdin {
23
23
}
24
24
}
25
25
26
+ impl AsFd for Stdin {
27
+ #[ inline]
28
+ fn as_fd ( & self ) -> BorrowedFd < ' _ > {
29
+ unsafe { BorrowedFd :: borrow_raw ( 0 ) }
30
+ }
31
+ }
32
+
26
33
impl io:: Read for Stdin {
27
34
fn read ( & mut self , data : & mut [ u8 ] ) -> io:: Result < usize > {
28
35
self . read_vectored ( & mut [ IoSliceMut :: new ( data) ] )
@@ -51,6 +58,13 @@ impl AsRawFd for Stdout {
51
58
}
52
59
}
53
60
61
+ impl AsFd for Stdout {
62
+ #[ inline]
63
+ fn as_fd ( & self ) -> BorrowedFd < ' _ > {
64
+ unsafe { BorrowedFd :: borrow_raw ( 1 ) }
65
+ }
66
+ }
67
+
54
68
impl io:: Write for Stdout {
55
69
fn write ( & mut self , data : & [ u8 ] ) -> io:: Result < usize > {
56
70
self . write_vectored ( & [ IoSlice :: new ( data) ] )
@@ -82,6 +96,13 @@ impl AsRawFd for Stderr {
82
96
}
83
97
}
84
98
99
+ impl AsFd for Stderr {
100
+ #[ inline]
101
+ fn as_fd ( & self ) -> BorrowedFd < ' _ > {
102
+ unsafe { BorrowedFd :: borrow_raw ( 2 ) }
103
+ }
104
+ }
105
+
85
106
impl io:: Write for Stderr {
86
107
fn write ( & mut self , data : & [ u8 ] ) -> io:: Result < usize > {
87
108
self . write_vectored ( & [ IoSlice :: new ( data) ] )
0 commit comments