ThreeRoundedSquares
ThreeRoundedSquares

Reputation: 1

Use enum variant as only its struct value

I have an app that has 2 functions that take a type we’ll call T and U. They are stored in an enum that looks like this:

#[derive(Serialize, Deserialize)]
#[serde(untagged)]
enum V {
    T { w: String },
    U { x: i32 },
}

This is pretty simplified, the real enum has a lot of nested structs. What I’m wondering is, can I in any way get the inner value (in a match or otherwise) like I could with a tuple? Could I use a tuple for this? Here’s the functions:

fn t(param: V/*::T*/) {}
fn u(param: V/*::U*/) {}

I can’t just use the ::* to do it, because enum variants aren’t considered types. If this isn’t possible, I can just refactor to pass the values into the function instead. Any help would be great, thanks!

Upvotes: 0

Views: 37

Answers (0)

Related Questions