2020-11-15 21:54:47 +01:00
|
|
|
module io
|
|
|
|
|
|
|
|
// ReaderWriter represents a stream that can be read from and wrote to
|
|
|
|
pub interface ReaderWriter {
|
|
|
|
// from Reader
|
|
|
|
read(mut buf []byte) ?int
|
2020-12-16 18:22:26 +01:00
|
|
|
// from Writer
|
2020-11-15 21:54:47 +01:00
|
|
|
write(buf []byte) ?int
|
|
|
|
}
|
|
|
|
|
2020-12-16 18:22:26 +01:00
|
|
|
// ReaderWriterImpl is a ReaderWriter that can be made from
|
2020-11-15 21:54:47 +01:00
|
|
|
// a seperate reader and writer (see fn make_readerwriter)
|
|
|
|
struct ReaderWriterImpl {
|
|
|
|
r Reader
|
|
|
|
w Writer
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn (mut r ReaderWriterImpl) read(mut buf []byte) ?int {
|
|
|
|
return r.r.read(mut buf)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn (mut r ReaderWriterImpl) write(buf []byte) ?int {
|
|
|
|
return r.w.write(buf)
|
|
|
|
}
|
|
|
|
|
|
|
|
// make_readerwriter takes a rstream and a wstream and makes
|
|
|
|
// an rwstream with them
|
|
|
|
pub fn make_readerwriter(r Reader, w Writer) ReaderWriterImpl {
|
2020-12-16 18:22:26 +01:00
|
|
|
return {
|
|
|
|
r: r
|
|
|
|
w: w
|
|
|
|
}
|
2020-11-15 21:54:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Zzz_CoerceInterfaceTableGeneration {
|
|
|
|
}
|
|
|
|
|
|
|
|
fn (_ Zzz_CoerceInterfaceTableGeneration) write(buf []byte) ?int {
|
2021-01-12 11:43:55 +01:00
|
|
|
return none
|
2020-11-15 21:54:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn (_ Zzz_CoerceInterfaceTableGeneration) read(mut buf []byte) ?int {
|
2021-01-12 11:43:55 +01:00
|
|
|
return none
|
2020-11-15 21:54:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn zzz_reader_writer_coerce_compiler() {
|
|
|
|
x := Zzz_CoerceInterfaceTableGeneration{}
|
|
|
|
_ := make_readerwriter(x, x)
|
|
|
|
}
|