I'm using a macro which generates enums from a schema.graphql
file. One limitation of this macro is that I can't use #derive
on the generated enums/structs (e.g. #[derive(FromSqlRow)]
). So, as recommended by the crate author, I resorted to writing my own identical enums with From
implementations to convert back and forth, e.g.:
impl From<&TransactionType> for models::TransactionType {
fn from(x: &TransactionType) -> models::TransactionType {
match x {
TransactionType::Deposit => models::TransactionType::Deposit,
TransactionType::Withdraw => models::TransactionType::Withdraw,
TransactionType::Payout => models::TransactionType::Payout,
TransactionType::Rollback => models::TransactionType::Rollback,
}
}
}
impl From<&models::TransactionType> for TransactionType {
fn from(x: &models::TransactionType) -> TransactionType {
match x {
models::TransactionType::Deposit => TransactionType::Deposit,
models::TransactionType::Withdraw => TransactionType::Withdraw,
models::TransactionType::Payout => TransactionType::Payout,
models::TransactionType::Rollback => TransactionType::Rollback,
}
}
}
I was wondering if there existed a macro that could automate the above and if not, if it was feasible for a newbie to write one.
Thanks!