Reputation: 42769
I use this data structure in a project:
#[derive(Serialize, Deserialize)]
pub enum Field {
last_name(String),
first_name(String),
/* etc. */
}
#[derive(Serialize, Deserialize)]
pub struct Update {
pub id: Id,
pub field: Field,
}
The enum is not really useful by itself, I use it for deserialization of JSON. So is it possible to do something like that?
#[derive(Serialize, Deserialize)]
pub struct PersonUpdate {
pub id: Id,
pub field: enum {
last_name(String),
first_name(String),
}
}
Upvotes: 13
Views: 6247
Reputation: 15539
It is not possible, you must give it a name, like you did in the first example.
Upvotes: 16