diff --git a/wit-0.3.0-draft/stdio.wit b/wit-0.3.0-draft/stdio.wit index 6c99a56..c1bc8ac 100644 --- a/wit-0.3.0-draft/stdio.wit +++ b/wit-0.3.0-draft/stdio.wit @@ -1,17 +1,59 @@ +@since(version = 0.3.0-rc-2025-08-15) +interface stdio { + @since(version = 0.3.0-rc-2025-08-15) + enum error-code { + /// Input/output error + io, + /// Invalid or incomplete multibyte or wide character + illegal-byte-sequence, + /// Broken pipe + pipe, + } +} + @since(version = 0.3.0-rc-2025-08-15) interface stdin { + /// Return a stream for reading from stdin. + /// + /// This function returns a stream which provides data read from stdin, + /// and a future to signal read results. + /// + /// If the stream's readable end is dropped the future will resolve to success. + /// + /// If the stream's writable end is dropped the future will either resolve to + /// success if stdin was closed by the writer or to an error-code if reading + /// failed for some other reason. + /// + /// Multiple streams may be active at the same time. The behavior of concurrent + /// reads is implementation-specific. @since(version = 0.3.0-rc-2025-08-15) - get-stdin: func() -> stream; + read-via-stream: func() -> tuple, future>>; } @since(version = 0.3.0-rc-2025-08-15) interface stdout { + /// Write the given stream to stdout. + /// + /// If the stream's writable end is dropped this function will either return + /// success once the entire contents of the stream have been written or an + /// error-code representing a failure. + /// + /// Otherwise if there is an error the readable end of the stream will be + /// dropped and this function will return an error-code. @since(version = 0.3.0-rc-2025-08-15) - set-stdout: func(data: stream); + write-via-stream: async func(data: stream) -> result<_, error-code>; } @since(version = 0.3.0-rc-2025-08-15) interface stderr { + /// Write the given stream to stderr. + /// + /// If the stream's writable end is dropped this function will either return + /// success once the entire contents of the stream have been written or an + /// error-code representing a failure. + /// + /// Otherwise if there is an error the readable end of the stream will be + /// dropped and this function will return an error-code. @since(version = 0.3.0-rc-2025-08-15) - set-stderr: func(data: stream); + write-via-stream: async func(data: stream) -> result<_, error-code>; }