From 87a2b0dac1936c4fe3a9bec612a2807c8ba294fa Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Mon, 7 Mar 2022 16:37:34 +0100 Subject: [PATCH] Implement `IntoResponseParts` for `Option` (#838) --- axum-core/src/response/into_response_parts.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/axum-core/src/response/into_response_parts.rs b/axum-core/src/response/into_response_parts.rs index 5810bef7..e85855b1 100644 --- a/axum-core/src/response/into_response_parts.rs +++ b/axum-core/src/response/into_response_parts.rs @@ -80,6 +80,21 @@ pub trait IntoResponseParts { fn into_response_parts(self, res: ResponseParts) -> Result; } +impl IntoResponseParts for Option +where + T: IntoResponseParts, +{ + type Error = T::Error; + + fn into_response_parts(self, res: ResponseParts) -> Result { + if let Some(inner) = self { + inner.into_response_parts(res) + } else { + Ok(res) + } + } +} + /// Parts of a response. /// /// Used with [`IntoResponseParts`].