this post was submitted on 01 Jun 2022
8 points (100.0% liked)

Rust Programming

8140 readers
28 users here now

founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] OsrsNeedsF2P@lemmy.ml 1 points 2 years ago (1 children)

Can you give examples? From the description, it seems like most languages (like Java) can store data in enums?

[–] acabjones@lemmygrad.ml 4 points 2 years ago (1 children)

I think they mean that enum variants can contain fields, i.e. individual variants are themselves structs or tuple structs. AFAIK the closest thing to this in a C-like lang would be a tagged union type.

[–] lemtoman@lemmy.ml 3 points 2 years ago

oh yes thats what i mean. Coded in rust, loved this feature, went back to python a bit and became sad that I couldnt do the same. Feels stupid that a variable can be different types depending on the situation, and having a dataclass where just one field is relevant seems too dumb