-
Notifications
You must be signed in to change notification settings - Fork 132
feature Added serde Serialize and Deserialize for some Cql value types. Counter, CqlVarint, CqlDuration and CqlTimeuuid #1365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PRs must not have merge commits inside. They should be rebased on main
instead.
scylla-cql/src/value.rs
Outdated
impl From<i64> for Counter { | ||
fn from(value: i64) -> Self { | ||
Counter(value) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lorak-mmk I recall you are against such conversions, am I correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
// serde Serialize implementation for Counter | ||
#[cfg(feature = "serde")] | ||
impl serde::Serialize for Counter { | ||
fn serialize<S>(&self, serializer: S) -> StdResult<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer { | ||
serializer.serialize_i64(self.0) | ||
} | ||
} | ||
|
||
// serde Deserialize implementation for Counter | ||
#[cfg(feature = "serde")] | ||
impl<'de> serde::Deserialize<'de> for Counter { | ||
fn deserialize<D>(deserializer: D) -> StdResult<Self, D::Error> | ||
where | ||
D: serde::Deserializer<'de> { | ||
struct CounterVisitor; | ||
|
||
impl<'de> serde::de::Visitor<'de> for CounterVisitor { | ||
type Value = Counter; | ||
|
||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
formatter.write_str("Expecting i64 data type!") | ||
} | ||
|
||
fn visit_i64<E>(self, v: i64) -> StdResult<Self::Value, E> | ||
where | ||
E: serde::de::Error, { | ||
Ok(Counter(v)) | ||
} | ||
} | ||
|
||
deserializer.deserialize_i64(CounterVisitor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Why do need to manually implement serde traits? I'd think that the #[derive(serde::Deserialize)]
should do the job.
/// | ||
/// serde traits not necessary. use chrono::DateTime<chrono::Utc> | ||
#[derive(Clone, Copy, PartialEq, Eq, Debug)] | ||
pub struct CqlTimestamp(pub i64); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
♻️ This comment is unclear. What are serde trait not necessary for? How is the user supposed to use chrono::DateTime
and what for?
Please fill the whole pre-review checklist; don't delete any entries from it. |
Change Summary
Added serde Derive traits to CqlTimeuuid, Counter, CqlVarint and CqlDuration