Skip to content
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

Add Option<DateTime> outputs for various serde helpers (ts_seconds, etc) #301

Closed
manifest opened this issue Jan 27, 2019 · 3 comments
Closed

Comments

@manifest
Copy link
Contributor

manifest commented Jan 27, 2019

The following doesn't work now:

#[derive(Debug, Serialize, Deserialize)]
struct Object {
    #[serde(with = "ts_seconds")]
    time: Option<DateTime<Utc>>,
}
error[E0308]: mismatched types
  --> src/db/rtc.rs:36:17
   |
36 | #[derive(Debug, Serialize, Deserialize)]
   |                 ^^^^^^^^^ expected struct `chrono::datetime::DateTime`, found enum `std::option::Option`
   |
   = note: expected type `&chrono::datetime::DateTime<chrono::offset::utc::Utc>`
              found type `&'__a std::option::Option<chrono::datetime::DateTime<chrono::offset::utc::Utc>>`

error[E0308]: match arms have incompatible types
  --> src/db/rtc.rs:36:28
   |
36 | #[derive(Debug, Serialize, Deserialize)]
   |                            -----------
   |                            |
   |                            expected enum `std::option::Option`, found struct `chrono::datetime::DateTime`
   |                            match arm with an incompatible type
   |                            in this macro invocation
   |
   = note: expected type `std::option::Option<chrono::datetime::DateTime<_>>`
              found type `chrono::datetime::DateTime<_>`

error[E0308]: match arms have incompatible types
  --> src/db/rtc.rs:36:28
   |
36 | #[derive(Debug, Serialize, Deserialize)]
   |                            -----------
   |                            |
   |                            expected enum `std::option::Option`, found struct `chrono::datetime::DateTime`
   |                            match arm with an incompatible type
   |                            in this macro invocation
   |
   = note: expected type `std::option::Option<chrono::datetime::DateTime<_>>`
              found type `chrono::datetime::DateTime<_>`
@manifest
Copy link
Contributor Author

I've just added a PR with these new modules:

  • ts_nanoseconds_option
  • ts_milliseconds_option
  • ts_seconds_option

They all reuse current Serializers and Deserializers' Visitors.

@quodlibetor quodlibetor changed the title Add Serialize/Deserialize for Option<DateTime> Add Option<DateTime> outputs for various serde helpers (ts_seconds, etc) Jan 29, 2019
@elpiel
Copy link
Contributor

elpiel commented May 28, 2019

Is this still on the roadmap/workings?

@quodlibetor
Copy link
Contributor

This is now merged.

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

No branches or pull requests

3 participants