#`anytype` for Writer interfaces

1 messages · Page 1 of 1 (latest)

hybrid oyster
#

Is there an anytype like thing, but for Writer interfaces?
Basically a struct field will take any type of Writer, but I'm having trouble expressing that to Zig..

coral tide
#

not sure what you mean but there's std.io.AnyWriter if you want a type-erased writer, like std.io.AnyReader

#

or potentially std.io.GenericWriter if you just want to give it a function and an error set

hybrid oyster
#
writer: std.io.AnyWriter,

pub fn init(writer: anytype) Self {
    return .{
        .writer = writer,
    };
}
#

im trying to make it work for any type of writer basically

coral tide
#

writer.any()

hybrid oyster
#

oh wow

#

that worked