Implement IntoResponseParts for Option<T> (#838)

This commit is contained in:
David Pedersen 2022-03-07 16:37:34 +01:00 committed by GitHub
parent 843437b501
commit 87a2b0dac1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -80,6 +80,21 @@ pub trait IntoResponseParts {
fn into_response_parts(self, res: ResponseParts) -> Result<ResponseParts, Self::Error>;
}
impl<T> IntoResponseParts for Option<T>
where
T: IntoResponseParts,
{
type Error = T::Error;
fn into_response_parts(self, res: ResponseParts) -> Result<ResponseParts, Self::Error> {
if let Some(inner) = self {
inner.into_response_parts(res)
} else {
Ok(res)
}
}
}
/// Parts of a response.
///
/// Used with [`IntoResponseParts`].