I'm working on a text based language for a proprietary DBMS so developers that use it can take advantage of version control, linters, etc. It takes the text based language, does a kind of "diff" against the schema defined in the proprietary file format, before writing the changes. I've represented what kind of change has taken place using enums in the following way:
#[derive(Debug, Serialize, Deserialize, Clone)]
struct Table {
pub id: usize,
pub name: String,
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
enum TableKind {
Created(Table),
Modified(Table),
UnModified(Table),
Deleted(Table),
}
impl From<TableKind> for Table {
fn from(value: TableKind) -> Self {
match value {
TableKind::Created(table)
| TableKind::Deleted(table)
| TableKind::Modified(table)
| TableKind::UnModified(table) => {
table
}
}
}
}
The enum is then used later in a pattern match to dictate behaviour, and I unwrap it to get the underlying table.
Is this idiomatic or is there a better way to do this? Coming from a C++ background.