1
- use super :: { AsyncInputStream , AsyncOutputStream } ;
1
+ use super :: { AsyncInputStream , AsyncOutputStream , AsyncRead , AsyncWrite , Result } ;
2
2
use std:: cell:: LazyCell ;
3
3
use wasi:: cli:: terminal_input:: TerminalInput ;
4
4
use wasi:: cli:: terminal_output:: TerminalOutput ;
@@ -19,25 +19,30 @@ pub fn stdin() -> Stdin {
19
19
}
20
20
}
21
21
22
- impl std:: ops:: Deref for Stdin {
23
- type Target = AsyncInputStream ;
24
- fn deref ( & self ) -> & AsyncInputStream {
25
- & self . stream
26
- }
27
- }
28
- impl std:: ops:: DerefMut for Stdin {
29
- fn deref_mut ( & mut self ) -> & mut AsyncInputStream {
30
- & mut self . stream
31
- }
32
- }
33
-
34
22
impl Stdin {
35
23
/// Check if stdin is a terminal.
36
24
pub fn is_terminal ( & self ) -> bool {
37
25
LazyCell :: force ( & self . terminput ) . is_some ( )
38
26
}
39
27
}
40
28
29
+ impl AsyncRead for Stdin {
30
+ #[ inline]
31
+ async fn read ( & mut self , buf : & mut [ u8 ] ) -> Result < usize > {
32
+ self . stream . read ( buf) . await
33
+ }
34
+
35
+ #[ inline]
36
+ async fn read_to_end ( & mut self , buf : & mut Vec < u8 > ) -> Result < usize > {
37
+ self . stream . read_to_end ( buf) . await
38
+ }
39
+
40
+ #[ inline]
41
+ fn as_async_input_stream ( & self ) -> Option < & AsyncInputStream > {
42
+ Some ( & self . stream )
43
+ }
44
+ }
45
+
41
46
/// Use the program's stdout as an `AsyncOutputStream`.
42
47
#[ derive( Debug ) ]
43
48
pub struct Stdout {
@@ -61,15 +66,25 @@ impl Stdout {
61
66
}
62
67
}
63
68
64
- impl std :: ops :: Deref for Stdout {
65
- type Target = AsyncOutputStream ;
66
- fn deref ( & self ) -> & AsyncOutputStream {
67
- & self . stream
69
+ impl AsyncWrite for Stdout {
70
+ # [ inline ]
71
+ async fn write ( & mut self , buf : & [ u8 ] ) -> Result < usize > {
72
+ self . stream . write ( buf ) . await
68
73
}
69
- }
70
- impl std:: ops:: DerefMut for Stdout {
71
- fn deref_mut ( & mut self ) -> & mut AsyncOutputStream {
72
- & mut self . stream
74
+
75
+ #[ inline]
76
+ async fn flush ( & mut self ) -> Result < ( ) > {
77
+ self . stream . flush ( ) . await
78
+ }
79
+
80
+ #[ inline]
81
+ async fn write_all ( & mut self , buf : & [ u8 ] ) -> Result < ( ) > {
82
+ self . stream . write_all ( buf) . await
83
+ }
84
+
85
+ #[ inline]
86
+ fn as_async_output_stream ( & self ) -> Option < & AsyncOutputStream > {
87
+ self . stream . as_async_output_stream ( )
73
88
}
74
89
}
75
90
@@ -96,15 +111,25 @@ impl Stderr {
96
111
}
97
112
}
98
113
99
- impl std :: ops :: Deref for Stderr {
100
- type Target = AsyncOutputStream ;
101
- fn deref ( & self ) -> & AsyncOutputStream {
102
- & self . stream
114
+ impl AsyncWrite for Stderr {
115
+ # [ inline ]
116
+ async fn write ( & mut self , buf : & [ u8 ] ) -> Result < usize > {
117
+ self . stream . write ( buf ) . await
103
118
}
104
- }
105
- impl std:: ops:: DerefMut for Stderr {
106
- fn deref_mut ( & mut self ) -> & mut AsyncOutputStream {
107
- & mut self . stream
119
+
120
+ #[ inline]
121
+ async fn flush ( & mut self ) -> Result < ( ) > {
122
+ self . stream . flush ( ) . await
123
+ }
124
+
125
+ #[ inline]
126
+ async fn write_all ( & mut self , buf : & [ u8 ] ) -> Result < ( ) > {
127
+ self . stream . write_all ( buf) . await
128
+ }
129
+
130
+ #[ inline]
131
+ fn as_async_output_stream ( & self ) -> Option < & AsyncOutputStream > {
132
+ self . stream . as_async_output_stream ( )
108
133
}
109
134
}
110
135
0 commit comments