Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive pubsub example in docs is not working #586

Closed
nazar-pc opened this issue Sep 21, 2020 · 3 comments · Fixed by #588
Closed

Derive pubsub example in docs is not working #586

nazar-pc opened this issue Sep 21, 2020 · 3 comments · Fixed by #588

Comments

@nazar-pc
Copy link
Contributor

nazar-pc commented Sep 21, 2020

I've copy-pasted the example given (even though it is not complete) and got this compile-time error:

error[E0271]: type mismatch resolving `<jsonrpc_pubsub::IoDelegate<sub::RpcImpl, Arc<Session>> as IntoIterator>::Item == (std::string::String, RemoteProcedure<()>)`
  --> src/rpc.rs:95:8
   |
95 |     io.extend_with(sub::RpcImpl::default().to_delegate());
   |        ^^^^^^^^^^^ expected struct `Arc`, found `()`
   |
   = note: expected tuple `(std::string::String, RemoteProcedure<Arc<Session>>)`
              found tuple `(std::string::String, RemoteProcedure<()>)`

I'm using current git master because I don't want to mess with futures 0.1.

Any ideas what is wrong here? Also having a full example in there would help to make sure it doesn't regress.

UPD: Seems to be caused by IoHandler::new(); instead of PubSubHandler::new(MetaIoHandler::default()), but now a new error:

error[E0277]: the trait bound `Session: Default` is not satisfied
  --> src/rpc.rs:82:37
   |
82 |     let server = ServerBuilder::new(io)
   |                                     ^^ the trait `Default` is not implemented for `Session`
   | 
  ::: /home/nazar-pc/.cargo/git/checkouts/jsonrpc-22a65938f7d26b63/92e3c14/ws/src/server_builder.rs:37:12
   |
37 |         T: Into<core::MetaIoHandler<M, S>>,
   |            ------------------------------- required by this bound in `ServerBuilder::<M, S>::new`
   |
   = note: required because of the requirements on the impl of `Default` for `Arc<Session>`

UPD 2: pubsub/examples/pubsub.rs is also broken, starting with context.sender.clone() that needs to be context.sender() to there is no such thing as an acquire/release load for obvious reasons; did it ever work at all?

@tomusdrw
Copy link
Contributor

@nazar-pc Could you clarify which example do you mean?

  1. The first error indeed like using IoHandler in pub-sub examples (Metadata defaults to ())
  2. To overcome the second error you need to use ServerBuilder::with_meta_extractor.

The reason for this is that pubsub requires the Session object to be created by the transport layer (so that we can push updates to the client) - there is no Default there.

@nazar-pc
Copy link
Contributor Author

I'm talking about Pub/Sub Example here: https://docs.rs/jsonrpc-derive/15.0.0/jsonrpc_derive/

@tomusdrw
Copy link
Contributor

Closed by #588

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants