scylladb / scylla-rust-driver

Async CQL driver for Rust, optimized for ScyllaDB!
Apache License 2.0
556 stars 94 forks source link

Serialization / Deserialization derive macros should work for enums without data #923

Open Lorak-mmk opened 7 months ago

Lorak-mmk commented 7 months ago

This looks like it can be a common case that users want to use structs like in this forum question: https://forum.scylladb.com/t/can-we-make-an-enum-serializable-so-it-can-go-to-and-from-a-cqlvalue-in-rust/1242 While I don't see any sensible way to derive for arbitrary enums, we could add support for enums without data. I think this shouldn't be too hard. The main question is how to specify the type to serialize to (i32, u8 etc)?

wprzytula commented 4 months ago

The main question is how to specify the type to serialize to (i32, u8 etc)?

We could require that it be specified as a derive macro's attribute, e.g.:

#[derive(SerializeCql)]
#[enum_repr(i32)]
enum MyEnum {
  A = 0,
  B = 1,
}
wprzytula commented 2 months ago

Part of #962.