scylla-rust-driver
scylla-rust-driver copied to clipboard
Scylla DB Timestamp: ValueList, FromRow, and Serialize without 3 layers of wrapping.
I need to have a struct like:
#[derive(Debug, FromRow, ValueList, Serialize)]
struct Task
{
action : i64,
dt : chrono::Duration
}
The problem is that this does not implement ValueList nor Serialize for Serde even though Timestamp is represented as chrono::Duration. However, If i store it as
#[derive(Debug, FromRow, ValueList, Serialize)]
struct Task
{
action : i64,
dt : scylla::frame::value::Timestamp
}
In this scenario, the difficulty is that Timestamp does not implement Serialize from serde.
I would like to avoid having to construct a struct to wrap the scylla::frame::value::Timestamp which wraps the chrono::Duration, but that seems to be the requirement and I would like to avoid that if possible. Especially because this would require me to implement also FromRow and Value list for my wrapper on a wrapper on a wrapper on a i64.
Serde provides some workarounds for third-party types that do not implement Serialize
/Deserialize
; check out this page: https://serde.rs/field-attrs.html and the serialize_with
, deserialize_with
and with
attributes.
I'd like to implement something similar for the new trait/procedural macro DeserializeCql
which will be introduced when the work in https://github.com/scylladb/scylla-rust-driver/pull/665 gets merged.