Serializes and deserializes ISO civil dates (YYYY-MM-DD) for Rust REST DTOs and broker payloads. Reuse when working with Serde and time types.
// Source: https://github.com/constructorfabric/gears-rust | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
//! ISO civil dates shared by REST DTOs and broker payloads.
use serde::{Deserialize, Deserializer, Serializer};
use time::Date;
/// Serialize a date as `YYYY-MM-DD`.
/// # Errors
/// Returns serialization or format errors.
#[allow(
clippy::trivially_copy_pass_by_ref,
reason = "serde with requires a borrowed field serializer"
)]
pub fn serialize<S: Serializer>(date: &Date, serializer: S) -> Result<S::Ok, S::Error> {
let format = time::format_description::parse_borrowed::<1>("[year]-[month]-[day]")
.map_err(serde::ser::Error::custom)?;
let text = date.
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key