Skip to content

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

didoloan
Copy link

Change Summary

Added serde Derive traits to CqlTimeuuid, Counter, CqlVarint and CqlDuration

  • [ x] I have split my patch into logically separate commits.
  • [ x] All commit messages clearly explain what they change and why.
  • [ x] PR description sums up the changes and reasons why they should be introduced.

Copy link

cargo semver-checks found no API-breaking changes in this PR.
Checked commit: 03b2e91

Copy link
Collaborator

@wprzytula wprzytula left a 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.

Comment on lines 28 to 33
impl From<i64> for Counter {
fn from(value: i64) -> Self {
Counter(value)
}
}

Copy link
Collaborator

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?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Comment on lines +28 to +60
// 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)
Copy link
Collaborator

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.

Comment on lines +712 to 715
///
/// serde traits not necessary. use chrono::DateTime<chrono::Utc>
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct CqlTimestamp(pub i64);
Copy link
Collaborator

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?

@wprzytula
Copy link
Collaborator

Please fill the whole pre-review checklist; don't delete any entries from it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants