#toml #chrono #time #serde #serialize-deserialize

toml-datetime-compat

Simple conversion of toml_datetime types from/to chrono and time

5 unstable releases

0.3.0 Apr 21, 2024
0.2.0 Jan 15, 2023
0.1.2 Jan 11, 2023
0.1.1 Jan 11, 2023
0.1.0 Jan 11, 2023

#2568 in Encoding

Download history 9/week @ 2024-11-23 23/week @ 2024-11-30 36/week @ 2024-12-07 30/week @ 2024-12-14 42/week @ 2024-12-21 3/week @ 2024-12-28 19/week @ 2025-01-04 58/week @ 2025-01-11 54/week @ 2025-01-18 13/week @ 2025-01-25 53/week @ 2025-02-01 54/week @ 2025-02-08 99/week @ 2025-02-15 61/week @ 2025-02-22 52/week @ 2025-03-01

288 downloads per month
Used in simplistis

MIT license

32KB
635 lines

toml-datetime-compat

Adds a functionality to easily convert between toml_datetime's and chrono's/time's types.

Both with the serde derive macros:

#[derive(Deserialize, Serialize)]
struct SomeDateTimes {
    #[serde(with = "toml_datetime_compat")]
    chrono_naive_date: chrono::NaiveDate,
    #[serde(with = "toml_datetime_compat")]
    chrono_naive_time: chrono::NaiveTime,
    #[serde(with = "toml_datetime_compat")]
    chrono_naive_date_time: chrono::NaiveDateTime,
    #[serde(with = "toml_datetime_compat")]
    chrono_date_time_utc: chrono::DateTime<chrono::Utc>,
    #[serde(with = "toml_datetime_compat")]
    chrono_date_time_offset: chrono::DateTime<chrono::FixedOffset>,
    #[serde(with = "toml_datetime_compat")]
    time_date: time::Date,
    #[serde(with = "toml_datetime_compat")]
    time_time: time::Time,
    #[serde(with = "toml_datetime_compat")]
    time_primitive_date_time: time::PrimitiveDateTime,
    #[serde(with = "toml_datetime_compat")]
    time_offset_date_time: time::OffsetDateTime,"#
}

And by introducing a new trait ToFromToml that adds to_toml and from_toml functions to the relevant structs from chrono and time.

Dependencies

~0.4–1.5MB
~32K SLoC