#how to set the type of a fn arg that is any Reader?

1 messages · Page 1 of 1 (latest)

proper stump
#

You have to use anytype

nimble jewel
#

Because std.mem.Allocator is a struct but std.io.Reader is a function.

proper stump
#

Unfortunately zig doesn't support this kind of generic trait parameters.

rancid nymph
#

Different ways of doing interfaces: generics with duck typing, or a struct with a type erased pointer. It seems that the newer io.AnyReader is done in the type erased style of Allocator, but most sutff in the standard library is written around the generic style.

proper stump
#

Usually I just give the parameter a specific implementation type (e.g. File.Reader ) for the intellisense while I'm writing it, and then change it once I'm done with the function.

#

It's not great, unfortunately.

rancid nymph
#

Yes, std.io.Reader is a generic type, i.e. a function that produces a type.

#

You'll have to use anytype, that's how those reader interfaces work currently.