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

implement this_cap() as a method of Params

Open dwrensha opened this issue 1 year ago • 2 comments

Fixes #87.

dwrensha avatar Jan 12 '24 13:01 dwrensha

Codecov Report

:x: Patch coverage is 60.86957% with 9 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 52.02%. Comparing base (d4d96aa) to head (3f18f6c). :warning: Report is 268 commits behind head on master.

Files with missing lines Patch % Lines
capnp-rpc/src/local.rs 70.00% 3 Missing :warning:
capnp-rpc/src/rpc.rs 70.00% 3 Missing :warning:
capnp/src/capability.rs 0.00% 3 Missing :warning:
Additional details and impacted files
@@           Coverage Diff           @@
##           master     #473   +/-   ##
=======================================
  Coverage   52.02%   52.02%           
=======================================
  Files          69       69           
  Lines       33957    33976   +19     
=======================================
+ Hits        17665    17676   +11     
- Misses      16292    16300    +8     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Jan 12 '24 13:01 codecov[bot]

One downside to this approach: it adds an extra heap allocation on the server side of every remote procedure call, because we do client.add_ref() to populate the this_cap field of Params.

The natural way to avoid that allocation would be to somehow pass a &Box<dyn ClientHook> instead. That could be accomplished by adding a new &Box<dyn ClientHook> parameter to every Server method (i.e. in addition to the existing Params and Results parameters), but doing so would add a lot of boilterplate for end users. A better approach might be to add a new CallContext<'a> struct (similar to what capnproto-c++ has) that holds the Params, Results, and also a &'a Box<dyn ClientHook> representing this_cap.

dwrensha avatar Jan 12 '24 13:01 dwrensha

https://github.com/capnproto/capnproto-rust/pull/595 includes 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