this post was submitted on 12 Mar 2022
3 points (100.0% liked)
Rust Programming
8858 readers
1 users here now
founded 6 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
You need to figure out the variant before you can access any fields.
or if you only need to do stuff on one type of point
However it looks like what you want is a struct that contains an enum and the coordinates.
Thanks! Yeah, I'm not actually trying to do anything useful with this code. Just testing out the concepts that I'm reading about.
Hmm, yeah, this is good. Coming from more object-oriented programming languages, my first intuition was to throw down a trait with those shared methods/fields, which then both coordinate-types implement, but that's rather clunky in Rust, since traits cannot define fields...