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

How to make this work with Chrono #19

Closed
lingfei1999 opened this issue Jun 15, 2023 · 1 comment
Closed

How to make this work with Chrono #19

lingfei1999 opened this issue Jun 15, 2023 · 1 comment

Comments

@lingfei1999
Copy link

lingfei1999 commented Jun 15, 2023

Hi, firstly, thanks for creating this useful library. While using it, I have problem with TypeDef and Chrono. This is what I have:

pub struct Test { 
  pub created_date: NaiveDateTime
}

I do have the lib chrono with features serde, and it prints out to string json just fine, but doesn't seem to work with derive TypeDef.

@dbeckwith
Copy link
Owner

Every field's type needs to implement the TypeDef trait in order for the derive to work, which NaiveDateTime doesn't because it comes from a different library. In that case, you can use the type_of option here, like so:

#[derive(TypeDef)]
pub struct Test { 
  #[type_def(type_of = "String")]
  pub created_date: NaiveDateTime
}

This tells the derive to generate types for that field that match the types of String, which seems to be appropriate here since NaiveDateTime serializes to a string.

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

2 participants