blob: ba44172eade89465c180dc77c102eabe3e6c1074 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
module io
// ReaderWriter represents a stream that can be read from and wrote to
pub interface ReaderWriter {
// from Reader
read(mut buf []byte) ?int
// from Writer
write(buf []byte) ?int
}
// ReaderWriterImpl is a ReaderWriter that can be made from
// a seperate reader and writer (see fn make_readerwriter)
struct ReaderWriterImpl {
r Reader
mut:
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 {
return ReaderWriterImpl{
r: r
w: w
}
}
|