#Is there a way to pass a reader as an argument?

1 messages · Page 1 of 1 (latest)

latent wadi
#

reader: anytype usually

versed quest
#

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

latent wadi
#

you could read the implementation of std.io.bufferedReader and std.io.BufferedReader to see a little how it could be approached

versed quest
#

it looks like it just returns std.io.BufferedReader(4096, type)

#

or: ```rs
std.io.BufferedReader(4096, @TypeOf(anytype))

jolly wigeon
#

rather look at the type definition

#
fn BufferedReader(comptime ReaderType: type, comptime buffer_size: usize) type {
    return struct {
        unbufferd_reader: ReaderType,
        // etc...
    };
}
unborn agate
#

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.

jolly wigeon
#

Wdym? You can, you just parametrize it

tired scroll
#

When I passed a reader to a function I used reader: std.io.AnyReader