viz-rs / viz

Fast, flexible, lightweight web framework for Rust
https://viz.rs
MIT License
345 stars 20 forks source link

Compilation error for `viz-core` on v0.7.0 #122

Closed Totodore closed 11 months ago

Totodore commented 11 months ago

When trying to compile viz-core:

error: future cannot be sent between threads safely
  --> /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/viz-core-0.7.0/src/handler/after.rs:27:48
   |
27 |       async fn call(&self, i: I) -> Self::Output {
   |  ________________________________________________^
28 | |         self.f.call(self.h.call(i).await).await
29 | |     }
   | |_____^ future created by async block is not `Send`
   |
note: future is not `Send` as this value is used across an await
  --> /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/viz-core-0.7.0/src/handler/after.rs:28:43
   |
28 |         self.f.call(self.h.call(i).await).await
   |                     --------------------  ^^^^^ await occurs here, with `self.h.call(i).await` maybe used later
   |                     |
   |                     has type `std::result::Result<O, error::Error>` which is not `Send`
29 |     }
   |     - `self.h.call(i).await` is later dropped here
   = note: required for the cast from `Pin<Box<...>>` to `Pin<Box<dyn Future<Output = Result<O, Error>> + Send>>`
   = note: the full name for the source type has been written to '/root/repos/socketioxide/target/debug/deps/viz_core-fd165c2c8ce6133a.long-type-12905923365472627885.txt'
   = note: the full name for the target type has been written to '/root/repos/socketioxide/target/debug/deps/viz_core-fd165c2c8ce6133a.long-type-15852316088634765815.txt'
help: consider further restricting type parameter `O`
   |
23 |     F: Handler<Result<O>, Output = Result<O>> + Clone, O: std::marker::Send
   |                                                      ~~~~~~~~~~~~~~~~~~~~~~

Adding a Send bound here on the O generic seems to resolve the issue :


#[async_trait]
impl<H, F, I, O> Handler<I> for After<H, F>
where
    I: Send + 'static,
    H: Handler<I, Output = Result<O>> + Clone,
    F: Handler<Result<O>, Output = Result<O>> + Clone,
    O: Send + 'static,
{
    type Output = F::Output;

    async fn call(&self, i: I) -> Self::Output {
        self.f.call(self.h.call(i).await).await
    }
}
fundon commented 11 months ago

Interesting. how it doesn't show up under stable or nightly on my env?

fundon commented 11 months ago

0.7.1 has be released.

But on my local, the problem cannot be reproduced.

Thank you for the feedback.