Enums with Fields in Diesel


I can create an Enum usable in queries by implementing FromSql and ToSql. (And AsExpression.) Is it possible to use an Enum that has fields? Maybe by implementing AsSqlRow? Here’s my use case:

I have an application that tracks payments. These payments can come from a number of sources including PayPal, Cash, and Check. If it is a check, I need a check number. If it is PayPal, I need a transaction id. So my enum looks like this:

enum PaymentType {

I’d like to store this enum in my payments table with string discriminator column having “check”, “cash”, or “paypal”. Also a column for check_number, which is null if not necessary, and a column for paypal_transaction, which is null if not necessary. Is this possible with Diesel?


https://gitter.im/diesel-rs/diesel might be a better place to ask this question.