use chrono::Duration; use duration_str::deserialize_duration_chrono; use serde::*; #[derive(Debug, Deserialize)] struct Config { #[serde(deserialize_with = "deserialize_duration_chrono")] time_ticker: Duration, } fn main() { let json = r#"{"time_ticker":"1m+30"}"#; let config: Config = serde_json::from_str(json).unwrap(); assert_eq!(config.time_ticker, Duration::seconds(60 + 30)); }