capnproto-rust icon indicating copy to clipboard operation
capnproto-rust copied to clipboard

Implement this_client()

Open ranfdev opened this issue 2 years ago • 1 comments

fixes #87.

One question though: this currently works well for a struct implementing a single interface. If a single struct implements multiple interfaces, there will be multiple this_client implementations, one for each interface. I'm not sure how this is going to handle multiple interfaces...

For example:

struct Calculator{}
impl calculator_add::Server for Calculator {
  fn add(&mut self, params, results) {...} 
}
impl calculator_sub::Server for Calculator {
  fn sub(&mut self, params, results) {
    let client = calculator_sub::Server::this_client(self); // Works perfectly.
    let client = calculator_add::Server::this_client(self); // OUCH, we are trying to get a `calculator_add::Client` from a `calculator_sub::Client`.
  } 
}

If the two interfaces share the same ClientHook anyway, this is fine. Do they? Else, it's going to be a problem.

ranfdev avatar Nov 27 '23 22:11 ranfdev

I implemented an alternative in #473.

dwrensha avatar Jan 12 '24 13:01 dwrensha

https://github.com/capnproto/capnproto-rust/pull/595 included a simpler solution: methods get self: Rc<Self>, which can be passed to capnp_rpc::new_client_from_rc().

dwrensha avatar Oct 28 '25 18:10 dwrensha