Skip to content

Commit 86488b0

Browse files
committed
feat: add IntoHandlerStatus implementation for Result
1 parent a4cc338 commit 86488b0

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/http/request.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ macro_rules! http_variable_get {
8585
/// in the `into_handler_status` method.
8686
///
8787
/// There are predefined implementations for `ngx_int_t`, [`Status`], [`HTTPStatus`],
88-
/// [`Option`] with value type implementing [`IntoHandlerStatus`].
88+
/// [`Option`] with value type implementing [`IntoHandlerStatus`],
89+
/// and [`Result`] with value and error types implementing [`IntoHandlerStatus`].
8990
pub trait IntoHandlerStatus
9091
where
9192
Self: Sized,
@@ -104,6 +105,16 @@ where
104105
}
105106
}
106107

108+
impl<T, E> IntoHandlerStatus for Result<T, E>
109+
where
110+
T: IntoHandlerStatus,
111+
E: IntoHandlerStatus,
112+
{
113+
fn into_handler_status(self, r: &Request) -> ngx_int_t {
114+
self.map_or_else(|err| err.into_handler_status(r), |val| val.into_handler_status(r))
115+
}
116+
}
117+
107118
impl IntoHandlerStatus for ngx_int_t {
108119
#[inline]
109120
fn into_handler_status(self, _r: &Request) -> ngx_int_t {

0 commit comments

Comments
 (0)