diff options
Diffstat (limited to 'codeless/server/src/dispatch.rs')
-rw-r--r-- | codeless/server/src/dispatch.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/codeless/server/src/dispatch.rs b/codeless/server/src/dispatch.rs index 41437b62a..2da0996e3 100644 --- a/codeless/server/src/dispatch.rs +++ b/codeless/server/src/dispatch.rs | |||
@@ -52,7 +52,7 @@ impl<R: Request> Responder<R> | |||
52 | } | 52 | } |
53 | 53 | ||
54 | 54 | ||
55 | pub fn parse_request_as<R>(raw: RawRequest) -> Result<::std::result::Result<(R::Params, Responder<R>), RawRequest>> | 55 | fn parse_request_as<R>(raw: RawRequest) -> Result<::std::result::Result<(R::Params, Responder<R>), RawRequest>> |
56 | where | 56 | where |
57 | R: Request, | 57 | R: Request, |
58 | R::Params: DeserializeOwned, | 58 | R::Params: DeserializeOwned, |
@@ -71,6 +71,25 @@ pub fn parse_request_as<R>(raw: RawRequest) -> Result<::std::result::Result<(R:: | |||
71 | Ok(Ok((params, responder))) | 71 | Ok(Ok((params, responder))) |
72 | } | 72 | } |
73 | 73 | ||
74 | pub fn handle_request<R, F>(req: &mut Option<RawRequest>, f: F) -> Result<()> | ||
75 | where | ||
76 | R: Request, | ||
77 | R::Params: DeserializeOwned, | ||
78 | R::Result: Serialize, | ||
79 | F: FnOnce(R::Params, Responder<R>) -> Result<()> | ||
80 | { | ||
81 | match req.take() { | ||
82 | None => Ok(()), | ||
83 | Some(r) => match parse_request_as::<R>(r)? { | ||
84 | Ok((params, responder)) => f(params, responder), | ||
85 | Err(r) => { | ||
86 | *req = Some(r); | ||
87 | Ok(()) | ||
88 | }, | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | |||
74 | pub fn expect_request<R>(io: &mut Io, raw: RawRequest) -> Result<Option<(R::Params, Responder<R>)>> | 93 | pub fn expect_request<R>(io: &mut Io, raw: RawRequest) -> Result<Option<(R::Params, Responder<R>)>> |
75 | where | 94 | where |
76 | R: Request, | 95 | R: Request, |
@@ -87,7 +106,7 @@ pub fn expect_request<R>(io: &mut Io, raw: RawRequest) -> Result<Option<(R::Para | |||
87 | Ok(ret) | 106 | Ok(ret) |
88 | } | 107 | } |
89 | 108 | ||
90 | pub fn parse_notification_as<N>(raw: RawNotification) -> Result<::std::result::Result<N::Params, RawNotification>> | 109 | fn parse_notification_as<N>(raw: RawNotification) -> Result<::std::result::Result<N::Params, RawNotification>> |
91 | where | 110 | where |
92 | N: Notification, | 111 | N: Notification, |
93 | N::Params: DeserializeOwned, | 112 | N::Params: DeserializeOwned, |