hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit d9fb4e18a44447eb1ce497b4c44945e6b1c3a84b
parent 3c0434105ff2ad5a9f37d02954c9a262a0ad0ae7
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat, 10 Apr 2021 11:27:01 -0400

io: implement unwrap for tee, limit

Diffstat:
Mio/limit.ha | 7+++++++
Mio/tee.ha | 7+++++++
2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/io/limit.ha b/io/limit.ha @@ -11,6 +11,7 @@ fn limited_stream_new(source: *stream, limit: size) *limited_stream = { stream = stream { name = strings::dup(source.name), closer = &limited_close, + unwrap = &limited_unwrap, ... }, source = source, @@ -58,3 +59,9 @@ fn limited_close(s: *stream) void = { free(s.name); free(s); }; + +fn limited_unwrap(s: *stream) *io::stream = { + assert(s.unwrap == &limited_unwrap); + let s = s: *limited_stream; + return s.source; +}; diff --git a/io/tee.ha b/io/tee.ha @@ -11,6 +11,7 @@ export fn tee(source: *stream, sink: *stream) *stream = { stream = stream { reader = &tee_read, closer = &tee_close, + unwrap = &tee_unwrap, ... }, source = source, @@ -32,3 +33,9 @@ fn tee_read(s: *stream, buf: []u8) (size | EOF | error) = { }; fn tee_close(s: *stream) void = free(s); + +fn tee_unwrap(s: *stream) *io::stream = { + assert(s.unwrap == &tee_unwrap); + let s = s: *tee_stream; + return s.source; +};