GithubHelp home page GithubHelp logo

Comments (3)

jonasbb avatar jonasbb commented on June 2, 2024

Hi, thanks for the suggestion. Do you have a concrete improvement in mind? All the examples with chrono::Duration on the DurationSeconds page use a more explicitly annotated DurationSeconds. The comparison table also lists that chrono::Duration is incompatible with the default format of u64.

use chrono::Duration;

#[serde_as]
#[derive(Deserialize, Serialize)]
struct Durations {
    #[serde_as(as = "DurationSeconds<i64>")]
    d_i64: Duration,
    #[serde_as(as = "DurationSeconds<f64>")]
    d_f64: Duration,
    #[serde_as(as = "DurationSeconds<String>")]
    d_string: Duration,
};

The example under "Advanced serde_as usage" used std::time::Duration. That is not directly obvious, since the import is hidden.

from serde_with.

xiaoas avatar xiaoas commented on June 2, 2024

imo

  • The example on the crate main page should use the explicit annotation, a example for chrono::Duration might be helpful as well.
  • The DurationSeconds page should have a example detailing using DurationSeconds<i64> on std::time::Duration, or using DurationSeconds<u64> on chrono::Duration are both incorrect.

What do you think?

from serde_with.

jonasbb avatar jonasbb commented on June 2, 2024

I made some changes in #576. I unhid the Duration import. I don't like the idea of showing wrong examples. I added some explanatory sentences and added some emphasis to the FORMAT support table for DurationSeconds/TimestampSeconds.

from serde_with.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.