#union(enum) initialize to void

1 messages · Page 1 of 1 (latest)

void lion
#

I currently have one union(enum) like:

const Node = union(enum) {
    none,
    ...
};

I try initializing it to "none":

const default_node = Node { .none };

and gets this error:

type 'main.Node' does not support array initialization syntax

(but it works if I change the type to u8 and init with 0 ? how i'm supposed to init a void field?)

barren snow
#

in a tagged union, if you don't annotate a member's type explicitly, it'll be of type void

void lion
#

yes right

barren snow
#

you initialise a void value with {} (or void{} but that might get removed)

void lion
#

just .none = {} ?

barren snow
#

yeah, that would be the prototypical way to initialise it

void lion
#

oh correct

#

thank you !