Skip to content

Commit 1976c7e

Browse files
committed
stdio: Update interfaces to support error results
1 parent 965cbde commit 1976c7e

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

wit-0.3.0-draft/stdio.wit

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,58 @@
1+
@since(version = 0.3.0-rc-2025-08-15)
2+
interface stdio {
3+
@since(version = 0.3.0-rc-2025-08-15)
4+
enum error-code {
5+
/// Input/output error
6+
io,
7+
/// Invalid or incomplete multibyte or wide character
8+
illegal-byte-sequence,
9+
/// Broken pipe
10+
pipe,
11+
}
12+
}
13+
114
@since(version = 0.3.0-rc-2025-08-15)
215
interface stdin {
16+
/// Return a stream for reading from stdin.
17+
///
18+
/// This function returns a `stream` which provides the data received from the
19+
/// file, and a `future` providing additional error information in case an
20+
/// error is encountered.
21+
///
22+
/// If the stream is dropped by the writer (`stream.read` returns `dropped`),
23+
/// the future will resolve either successfully if stdin was closed by the other
24+
/// end or an error if the read failed.
25+
///
26+
/// Multiple streams may be active at the same time. The behavior of concurrent
27+
/// reads is implementation-specific.
328
@since(version = 0.3.0-rc-2025-08-15)
4-
get-stdin: func() -> stream<u8>;
29+
read-stdin: func() -> tuple<stream<u8>, future<result<_, error-code>>>;
530
}
631

732
@since(version = 0.3.0-rc-2025-08-15)
833
interface stdout {
34+
/// Append from the given stream to stdout.
35+
///
36+
/// If the stream's writable end is dropped this function will either return
37+
/// success once the entire contents of the stream have been written or an
38+
/// error-code representing a failure.
39+
///
40+
/// Otherwise if there is an error the readable end of the stream will be
41+
/// dropped and this function will return an error-code.
942
@since(version = 0.3.0-rc-2025-08-15)
10-
set-stdout: func(data: stream<u8>);
43+
append-stdout: async func(data: stream<u8>) -> result<_, error-code>;
1144
}
1245

1346
@since(version = 0.3.0-rc-2025-08-15)
1447
interface stderr {
48+
/// Append from the given stream to stderr.
49+
///
50+
/// If the stream's writable end is dropped this function will either return
51+
/// success once the entire contents of the stream have been written or an
52+
/// error-code representing a failure.
53+
///
54+
/// Otherwise if there is an error the readable end of the stream will be
55+
/// dropped and this function will return an error-code.
1556
@since(version = 0.3.0-rc-2025-08-15)
16-
set-stderr: func(data: stream<u8>);
57+
append-stderr: async func(data: stream<u8>) -> result<_, error-code>;
1758
}

0 commit comments

Comments
 (0)