mirror of
https://github.com/tokio-rs/axum.git
synced 2024-11-26 09:08:05 +01:00
Implement IntoResponseParts
for Option<T>
(#838)
This commit is contained in:
parent
843437b501
commit
87a2b0dac1
1 changed files with 15 additions and 0 deletions
|
@ -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`].
|
||||
|
|
Loading…
Reference in a new issue