From 466f1e3867dce6bd84806df78a5dd38f0c7f03b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rube=CC=81n=20Dura=CC=81=20Tari=CC=81?= Date: Wed, 15 Jul 2020 01:55:50 +0200 Subject: [PATCH 1/2] Relax Sync bound on Fut required on sse upgrade async_std::spawn doesn't seem to require a Sync bound on any Futures used on it. tide::sse::upgrade will just spawn the Future returned by the Fn parameter. With this in mind, the Sync bound on that returned Future seems unnecessary. --- src/sse/upgrade.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sse/upgrade.rs b/src/sse/upgrade.rs index 9eff4b864..6f11e6622 100644 --- a/src/sse/upgrade.rs +++ b/src/sse/upgrade.rs @@ -13,7 +13,7 @@ pub fn upgrade(req: Request, handler: F) -> Response where State: Send + Sync + 'static, F: Fn(Request, Sender) -> Fut + Send + Sync + 'static, - Fut: Future> + Send + Sync + 'static, + Fut: Future> + Send + 'static, { let (sender, encoder) = async_sse::encode(); task::spawn(async move { From a56e6a9dc9ed3947c8a7708578d266f870c4fd03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rube=CC=81n=20Dura=CC=81=20Tari=CC=81?= Date: Mon, 20 Jul 2020 01:40:59 +0200 Subject: [PATCH 2/2] Relax Sync bound on Fut required on sse endpoint This commit also removes a PhantomData field from the SseEndpoint struct, since it doesn't seem to be required and it was turning the type !Sync. Removing it make the type Sync again, and allows us to remove the Sync bound from the returned Fut from the handler function. --- src/sse/endpoint.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/sse/endpoint.rs b/src/sse/endpoint.rs index dac364490..657253deb 100644 --- a/src/sse/endpoint.rs +++ b/src/sse/endpoint.rs @@ -16,12 +16,11 @@ pub fn endpoint(handler: F) -> SseEndpoint where State: Send + Sync + 'static, F: Fn(Request, Sender) -> Fut + Send + Sync + 'static, - Fut: Future> + Send + Sync + 'static, + Fut: Future> + Send + 'static, { SseEndpoint { handler: Arc::new(handler), __state: PhantomData, - __fut: PhantomData, } } @@ -31,18 +30,17 @@ pub struct SseEndpoint where State: Send + Sync + 'static, F: Fn(Request, Sender) -> Fut + Send + Sync + 'static, - Fut: Future> + Send + Sync + 'static, + Fut: Future> + Send + 'static, { handler: Arc, __state: PhantomData, - __fut: PhantomData, } impl Endpoint for SseEndpoint where State: Send + Sync + 'static, F: Fn(Request, Sender) -> Fut + Send + Sync + 'static, - Fut: Future> + Send + Sync + 'static, + Fut: Future> + Send + 'static, { fn call<'a>(&'a self, req: Request) -> BoxFuture<'a, Result> { let handler = self.handler.clone();