Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions compiler/pavexc_cli/template/app/src/configuration.rs.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::time::Duration, D::Error>
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<IncomingStream, std::io::Error> {
Expand Down
18 changes: 1 addition & 17 deletions docs/tutorials/quickstart/project/app/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::time::Duration, D::Error>
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<IncomingStream, std::io::Error> {
Expand Down
18 changes: 1 addition & 17 deletions examples/realworld/app/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::time::Duration, D::Error>
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<IncomingStream, std::io::Error> {
Expand Down
18 changes: 1 addition & 17 deletions examples/starter/app/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::time::Duration, D::Error>
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<IncomingStream, std::io::Error> {
Expand Down