google / tarpc

An RPC framework for Rust with a focus on ease of use.
MIT License
3.18k stars 194 forks source link

Readme example doesn't compile #456

Closed aaryanpunia closed 3 months ago

aaryanpunia commented 3 months ago

I was trying to implement the README example on the repository, and it doesn't compile, when using all the dependencies specified and copy pasting the code, I get the following error -

warning: unused imports: `Ready`, `self`
 --> src/main.rs:1:23
  |
1 | use futures::future::{self, Ready};
  |                       ^^^^  ^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0046]: not all trait items implemented, missing: `HelloFut`
  --> src/main.rs:21:1
   |
9  | #[tarpc::service]
   | ----------------- `HelloFut` from trait
...
21 | impl World for HelloServer {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `HelloFut` in implementation

For more information about this error, try `rustc --explain E0046`.
warning: `raft` (bin "raft") generated 1 warning
error: could not compile `raft` (bin "raft") due to 1 previous error; 1 warning emitted
tikue commented 3 months ago

Thanks for the report! I think I didn't fully update the example for the latest version. Can you try using version 0.34 (and you can remove the unused imports, too)?

tikue commented 3 months ago

I updated the readme; can you try again?

aaryanpunia commented 3 months ago

Now I get this error

error[E0277]: `impl futures_core::stream::Stream<Item = impl Future<Output = ()>>` is not a future
   --> src/main.rs:30:18
    |
30  |     tokio::spawn(server.execute(HelloServer.serve()));
    |     ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `impl futures_core::stream::Stream<Item = impl Future<Output = ()>>` is not a future
    |     |
    |     required by a bound introduced by this call
    |
    = help: the trait `Future` is not implemented for `impl futures_core::stream::Stream<Item = impl Future<Output = ()>>`
note: required by a bound in `tokio::spawn`
   --> /Users/aaryanpunia/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.38.0/src/task/spawn.rs:166:12
    |
164 |     pub fn spawn<F>(future: F) -> JoinHandle<F::Output>
    |            ----- required by a bound in this function
165 |     where
166 |         F: Future + Send + 'static,
    |            ^^^^^^ required by this bound in `spawn`

error[E0277]: `impl futures_core::stream::Stream<Item = impl Future<Output = ()>>` is not a future
  --> src/main.rs:30:5
   |
30 |     tokio::spawn(server.execute(HelloServer.serve()));
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `impl futures_core::stream::Stream<Item = impl Future<Output = ()>>` is not a future
   |
   = help: the trait `Future` is not implemented for `impl futures_core::stream::Stream<Item = impl Future<Output = ()>>`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `raft` (bin "raft") due to 2 previous errors
tikue commented 3 months ago

Oops, let's try this one more time! Sorry, just got off a plane and going on one hour of sleep...

Also note the additional import, use futures::prelude::*; .

aaryanpunia commented 3 months ago

Works now! thank you!

tikue commented 3 months ago

Thank you for helping make the documentation better!