diff --git a/compiler/pavexc_cli/template/app/src/configuration.rs.liquid b/compiler/pavexc_cli/template/app/src/configuration.rs.liquid index a89ef6a90..790af7e0e 100644 --- a/compiler/pavexc_cli/template/app/src/configuration.rs.liquid +++ b/compiler/pavexc_cli/template/app/src/configuration.rs.liquid @@ -40,26 +40,10 @@ pub struct ServerConfig { /// E.g. `1 minute` for a 1 minute timeout. /// /// Set the `PX_SERVER__GRACEFUL_SHUTDOWN_TIMEOUT` environment variable to override its value. - #[serde(deserialize_with = "deserialize_shutdown")] + #[serde(with = "pavex::time::fmt::serde::unsigned_duration::required")] pub graceful_shutdown_timeout: std::time::Duration, } -fn deserialize_shutdown<'de, D>(deserializer: D) -> Result -where - D: serde::Deserializer<'de>, -{ - use serde::Deserialize as _; - - let duration = pavex::time::SignedDuration::deserialize(deserializer)?; - if duration.is_negative() { - Err(serde::de::Error::custom( - "graceful shutdown timeout must be positive", - )) - } else { - duration.try_into().map_err(serde::de::Error::custom) - } -} - impl ServerConfig { /// Bind a TCP listener according to the specified parameters. pub async fn listener(&self) -> Result { diff --git a/docs/tutorials/quickstart/project/app/src/configuration.rs b/docs/tutorials/quickstart/project/app/src/configuration.rs index 2507f2f1f..cd8fb25d8 100644 --- a/docs/tutorials/quickstart/project/app/src/configuration.rs +++ b/docs/tutorials/quickstart/project/app/src/configuration.rs @@ -25,26 +25,10 @@ pub struct ServerConfig { /// E.g. `1 minute` for a 1 minute timeout. /// /// Set the `PX_SERVER__GRACEFUL_SHUTDOWN_TIMEOUT` environment variable to override its value. - #[serde(deserialize_with = "deserialize_shutdown")] + #[serde(with = "pavex::time::fmt::serde::unsigned_duration::required")] pub graceful_shutdown_timeout: std::time::Duration, } -fn deserialize_shutdown<'de, D>(deserializer: D) -> Result -where - D: serde::Deserializer<'de>, -{ - use serde::Deserialize as _; - - let duration = pavex::time::SignedDuration::deserialize(deserializer)?; - if duration.is_negative() { - Err(serde::de::Error::custom( - "graceful shutdown timeout must be positive", - )) - } else { - duration.try_into().map_err(serde::de::Error::custom) - } -} - impl ServerConfig { /// Bind a TCP listener according to the specified parameters. pub async fn listener(&self) -> Result { diff --git a/examples/realworld/app/src/configuration.rs b/examples/realworld/app/src/configuration.rs index 24d0cdc8d..604a03428 100644 --- a/examples/realworld/app/src/configuration.rs +++ b/examples/realworld/app/src/configuration.rs @@ -26,26 +26,10 @@ pub struct ServerConfig { /// E.g. `1 minute` for a 1 minute timeout. /// /// Set the `PX_SERVER__GRACEFUL_SHUTDOWN_TIMEOUT` environment variable to override its value. - #[serde(deserialize_with = "deserialize_shutdown")] + #[serde(with = "pavex::time::fmt::serde::unsigned_duration::required")] pub graceful_shutdown_timeout: std::time::Duration, } -fn deserialize_shutdown<'de, D>(deserializer: D) -> Result -where - D: serde::Deserializer<'de>, -{ - use serde::Deserialize as _; - - let duration = pavex::time::SignedDuration::deserialize(deserializer)?; - if duration.is_negative() { - Err(serde::de::Error::custom( - "graceful shutdown timeout must be positive", - )) - } else { - duration.try_into().map_err(serde::de::Error::custom) - } -} - impl ServerConfig { /// Bind a TCP listener according to the specified parameters. pub async fn listener(&self) -> Result { diff --git a/examples/starter/app/src/configuration.rs b/examples/starter/app/src/configuration.rs index 03aa39ecf..3bf2f2b93 100644 --- a/examples/starter/app/src/configuration.rs +++ b/examples/starter/app/src/configuration.rs @@ -37,26 +37,10 @@ pub struct ServerConfig { /// E.g. `1 minute` for a 1 minute timeout. /// /// Set the `PX_SERVER__GRACEFUL_SHUTDOWN_TIMEOUT` environment variable to override its value. - #[serde(deserialize_with = "deserialize_shutdown")] + #[serde(with = "pavex::time::fmt::serde::unsigned_duration::required")] pub graceful_shutdown_timeout: std::time::Duration, } -fn deserialize_shutdown<'de, D>(deserializer: D) -> Result -where - D: serde::Deserializer<'de>, -{ - use serde::Deserialize as _; - - let duration = pavex::time::SignedDuration::deserialize(deserializer)?; - if duration.is_negative() { - Err(serde::de::Error::custom( - "graceful shutdown timeout must be positive", - )) - } else { - duration.try_into().map_err(serde::de::Error::custom) - } -} - impl ServerConfig { /// Bind a TCP listener according to the specified parameters. pub async fn listener(&self) -> Result {