Update doc/note/io-input-output.md for io_bind

This commit is contained in:
Nigel Tao committed 2019-12-19 22:08:55 +11:00
1 parent 5256cb67d9
commit 46b2ae3e9c
1 file changed
+25 -2
+25 -2
View File
@@ -210,5 +210,28 @@ methods. Wuffs code does not reference an `io_buffer` directly.
## Binding
TODO: discuss `io_bind`, which temporarily adapts a slice of bytes into an
`io_buffer`.
An `io_bind` block temporarily adapts a slice of bytes as an `io_reader` or
`io_writer`. This is typically done to call other functions that take an
`io_reader` or `io_writer` as an argument.
```
var r : base.io_reader
var s : slice base.u8
etc
// Just before the io_bind, r's state is saved.
io_bind (io: r, data: s) {
// At the top of the block, r's data slice is set to s, and r's metadata is
// set so that ri = 0, pos = 0 and closed = false.
//
// Because r is an io_reader, not an io_writer, the wi metadata field is
// set to the slice length, not 0.
//
// r must be a local variable, but s can be an expression.
etc
}
// Just after the io_bind, r's state is restored.
```