I am exploring how to use FromRow
and SerializeCql
which seems to support all of the basic types. I would like to support using enums (for example see the PersonStatus
below.
Is it possible to coerce an enum
to work within FromRow
and SerializeCql
, are there any examples anywhere?
#[derive(Debug, FromRow, SerializeCql)]
pub struct Person {
pub uid: String,
pub first_name: String,
pub last_name: String,
pub contact: Vec<Contact>,
pub username: String,
pub password: String,
pub status: PersonStatus,
}
#[derive(Debug, FromUserType)]
pub enum PersonStatus {
Unverified = 0,
Active = 1,
ScheduledDelete = 2,
}
#[derive(Debug, FromRow, SerializeCql)]
pub struct Contact {
pub info: String, // email or mobile number
pub category:ContactType,
}
What is the alternative if using enum
is not possible? Would we just implement a full “deserialize struct” and “serialize struct” trait to translate and spit out the values for the scylla driver?
Looking at the driver code for how how serializing works gives me some hint that perhaps it might be possible to implement a serialization trait for the rust driver, but I’m not sure. Could an enum in the end users code go ahead and implement something like:
impl<T: SerializeCql> SerializeCql for Vec<T> {
fn serialize<'b>(
&self,
typ: &ColumnType,
writer: CellWriter<'b>,
) -> Result<WrittenCellProof<'b>, SerializationError> {
// special sauce stuff
}
}