@@ -5,7 +5,9 @@ use magnus::{
55} ;
66use std:: io:: Write ;
77use std:: sync:: { Arc , Mutex } ;
8- use wasmtime_wasi:: p2:: { OutputStream , Pollable , StdoutStream , StreamError , StreamResult } ;
8+ use tokio:: io:: AsyncWrite ;
9+ use wasmtime_wasi:: cli:: { IsTerminal , StdoutStream } ;
10+ use wasmtime_wasi:: p2:: { OutputStream , Pollable , StreamError , StreamResult } ;
911
1012/// A buffer that limits the number of bytes that can be written to it.
1113/// If the buffer is full, it will truncate the data.
@@ -14,6 +16,31 @@ pub struct OutputLimitedBuffer {
1416 inner : Arc < Mutex < OutputLimitedBufferInner > > ,
1517}
1618
19+ // No support for WASI P3, yet.
20+ impl AsyncWrite for OutputLimitedBuffer {
21+ fn poll_write (
22+ self : std:: pin:: Pin < & mut Self > ,
23+ _cx : & mut std:: task:: Context < ' _ > ,
24+ _buf : & [ u8 ] ,
25+ ) -> std:: task:: Poll < Result < usize , std:: io:: Error > > {
26+ std:: task:: Poll :: Ready ( Ok ( 0 ) )
27+ }
28+
29+ fn poll_flush (
30+ self : std:: pin:: Pin < & mut Self > ,
31+ _cx : & mut std:: task:: Context < ' _ > ,
32+ ) -> std:: task:: Poll < Result < ( ) , std:: io:: Error > > {
33+ std:: task:: Poll :: Ready ( Ok ( ( ) ) )
34+ }
35+
36+ fn poll_shutdown (
37+ self : std:: pin:: Pin < & mut Self > ,
38+ _cx : & mut std:: task:: Context < ' _ > ,
39+ ) -> std:: task:: Poll < Result < ( ) , std:: io:: Error > > {
40+ std:: task:: Poll :: Ready ( Ok ( ( ) ) )
41+ }
42+ }
43+
1744impl OutputLimitedBuffer {
1845 /// Creates a new [OutputLimitedBuffer] with the given underlying buffer
1946 /// and capacity.
@@ -33,12 +60,19 @@ impl Clone for OutputLimitedBuffer {
3360}
3461
3562impl StdoutStream for OutputLimitedBuffer {
36- fn stream ( & self ) -> Box < dyn OutputStream > {
63+ fn p2_stream ( & self ) -> Box < dyn OutputStream > {
64+ let cloned = self . clone ( ) ;
65+ Box :: new ( cloned)
66+ }
67+
68+ fn async_stream ( & self ) -> Box < dyn AsyncWrite + Send + Sync > {
3769 let cloned = self . clone ( ) ;
3870 Box :: new ( cloned)
3971 }
72+ }
4073
41- fn isatty ( & self ) -> bool {
74+ impl IsTerminal for OutputLimitedBuffer {
75+ fn is_terminal ( & self ) -> bool {
4276 false
4377 }
4478}
0 commit comments