#optional anyWriter as type of argument
1 messages · Page 1 of 1 (latest)
i assume your question is something like "why doesn't this work"?
you can't put any modifiers on anytype
if you want to require it to be optional, you can either do something like
pub fn myFunc(comptime LogType: type, log: ?LogType) void
or you can just use anytype and then inside the function use @typeInfo(@TypeOf(log)), check whether it is really optional, and use @compileError for a nice message if not
I sincerely don’t understand why there is a standard type for the allocator that can be specified, but not for the writer
i try use anytype and compiller write me error: expected optional type. those. when I send non-null to a function it is automatically non-optional
"comptime LogType: type" - It obviously doesn’t suit me because I use 2 different Writers. And sometimes I don’t want to send it to a function at all.
The writer is comptime interface, the allocator is a runtime one
The runtime one is a single type since is just a vtable we pass around
While the comptime one is Generic over the error/write/read function
which mean one reader/writer is different than another one