#Is there a way to pass a reader as an argument?
1 messages · Page 1 of 1 (latest)
that works for argument decls so thank you, but how would i express it as a struct field?
i dont think anytype works for that
you could read the implementation of std.io.bufferedReader and std.io.BufferedReader to see a little how it could be approached
it looks like it just returns std.io.BufferedReader(4096, type)
or: ```rs
std.io.BufferedReader(4096, @TypeOf(anytype))
rather look at the type definition
fn BufferedReader(comptime ReaderType: type, comptime buffer_size: usize) type {
return struct {
unbufferd_reader: ReaderType,
// etc...
};
}
You will not be able to put a generic reader in a struct, you can put a specific one (like a std.io.BufferedReader(4096, u8)) or the new type erased reader that I forget the name of.
Wdym? You can, you just parametrize it
When I passed a reader to a function I used reader: std.io.AnyReader