diff options
author | Aleksey Kladov <[email protected]> | 2018-08-10 21:56:19 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-10 21:56:19 +0100 |
commit | 52de08330f5052a1f10c5d46e1352ca86b622d71 (patch) | |
tree | 9f1adb749b2e4e344192e7060fcde8c748feede1 /crates/server/src/dispatch.rs | |
parent | bf42a75f1e9a86247067611fadbed48ea9d379b0 (diff) |
dedupe
Diffstat (limited to 'crates/server/src/dispatch.rs')
-rw-r--r-- | crates/server/src/dispatch.rs | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/crates/server/src/dispatch.rs b/crates/server/src/dispatch.rs index d9681db40..6a609f10e 100644 --- a/crates/server/src/dispatch.rs +++ b/crates/server/src/dispatch.rs | |||
@@ -9,20 +9,17 @@ use drop_bomb::DropBomb; | |||
9 | 9 | ||
10 | use ::{ | 10 | use ::{ |
11 | Result, | 11 | Result, |
12 | req::{Request, Notification}, | 12 | req::{ClientRequest, Notification}, |
13 | io::{Io, RawMsg, RawResponse, RawRequest, RawNotification}, | 13 | io::{Io, RawMsg, RawResponse, RawRequest, RawNotification}, |
14 | }; | 14 | }; |
15 | 15 | ||
16 | pub struct Responder<R: Request> { | 16 | pub struct Responder<R: ClientRequest> { |
17 | id: u64, | 17 | id: u64, |
18 | bomb: DropBomb, | 18 | bomb: DropBomb, |
19 | ph: PhantomData<R>, | 19 | ph: PhantomData<R>, |
20 | } | 20 | } |
21 | 21 | ||
22 | impl<R: Request> Responder<R> | 22 | impl<R: ClientRequest> Responder<R> |
23 | where | ||
24 | R::Params: DeserializeOwned, | ||
25 | R::Result: Serialize, | ||
26 | { | 23 | { |
27 | pub fn response(self, io: &mut Io, resp: Result<R::Result>) -> Result<()> { | 24 | pub fn response(self, io: &mut Io, resp: Result<R::Result>) -> Result<()> { |
28 | match resp { | 25 | match resp { |
@@ -52,11 +49,8 @@ impl<R: Request> Responder<R> | |||
52 | } | 49 | } |
53 | 50 | ||
54 | 51 | ||
55 | fn parse_request_as<R>(raw: RawRequest) -> Result<::std::result::Result<(R::Params, Responder<R>), RawRequest>> | 52 | fn parse_request_as<R: ClientRequest>(raw: RawRequest) |
56 | where | 53 | -> Result<::std::result::Result<(R::Params, Responder<R>), RawRequest>> |
57 | R: Request, | ||
58 | R::Params: DeserializeOwned, | ||
59 | R::Result: Serialize, | ||
60 | { | 54 | { |
61 | if raw.method != R::METHOD { | 55 | if raw.method != R::METHOD { |
62 | return Ok(Err(raw)); | 56 | return Ok(Err(raw)); |
@@ -73,9 +67,7 @@ fn parse_request_as<R>(raw: RawRequest) -> Result<::std::result::Result<(R::Para | |||
73 | 67 | ||
74 | pub fn handle_request<R, F>(req: &mut Option<RawRequest>, f: F) -> Result<()> | 68 | pub fn handle_request<R, F>(req: &mut Option<RawRequest>, f: F) -> Result<()> |
75 | where | 69 | where |
76 | R: Request, | 70 | R: ClientRequest, |
77 | R::Params: DeserializeOwned, | ||
78 | R::Result: Serialize, | ||
79 | F: FnOnce(R::Params, Responder<R>) -> Result<()> | 71 | F: FnOnce(R::Params, Responder<R>) -> Result<()> |
80 | { | 72 | { |
81 | match req.take() { | 73 | match req.take() { |
@@ -90,11 +82,8 @@ pub fn handle_request<R, F>(req: &mut Option<RawRequest>, f: F) -> Result<()> | |||
90 | } | 82 | } |
91 | } | 83 | } |
92 | 84 | ||
93 | pub fn expect_request<R>(io: &mut Io, raw: RawRequest) -> Result<Option<(R::Params, Responder<R>)>> | 85 | pub fn expect_request<R: ClientRequest>(io: &mut Io, raw: RawRequest) |
94 | where | 86 | -> Result<Option<(R::Params, Responder<R>)>> |
95 | R: Request, | ||
96 | R::Params: DeserializeOwned, | ||
97 | R::Result: Serialize, | ||
98 | { | 87 | { |
99 | let ret = match parse_request_as::<R>(raw)? { | 88 | let ret = match parse_request_as::<R>(raw)? { |
100 | Ok(x) => Some(x), | 89 | Ok(x) => Some(x), |