Supporting Capability in capnproto-rust

64 views
Skip to first unread message

Troy Farrell

unread,
Aug 27, 2021, 12:38:50 AM8/27/21
to Cap'n Proto
Hello everyone,

I posted a message to the Sandstorm list about trying to set a Capability field on a Params struct using capnproto-rust:

It seems that capnproto-rust does not support Capabilities.  I would like to know how difficult it would be to add this support.  I have sorted out how to generate the set_cap() method by modifying capnproto-rust/capnpc/src/codegen.rs:generate_setter.  I have not sorted out what code should be generated and larger design questions.

By design questions, I mean, for example, in capnproto-rust/capnpc/src/codegen_types.rs, does Capability fit as a member of pub enum Leaf?  (I expected to see AnyPointer there.)

I am inexperienced with both Rust and Cap'n Proto and eager to understand both better.  Your patience is appreciated.

Thanks,
Troy

David Renshaw

unread,
Aug 27, 2021, 8:26:12 AM8/27/21
to Troy Farrell, Cap'n Proto
Something like this should work:

let client: hello_capnp::hello::Client = capnp_rpc::new_client(HelloImpl);
let mut req = self.session_context.fulfill_request_request();
req.get().get_cap().set_as_capability(client.client.hook);

What'a happening here is that capnproto-rust does not have specific support for the :Capability type, so it falls back to a general AnyPointer.

The client.client.hook thing is admittedly ugly. I think we can make that nicer by adding an IntoInternalClientHook trait, as I commented here:
https://github.com/capnproto/capnproto-rust/issues/226#issuecomment-887604513


--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/9e911157-9dc2-4817-8824-e1482dc35746n%40googlegroups.com.

Troy Farrell

unread,
Aug 27, 2021, 9:51:41 AM8/27/21
to Cap'n Proto
Thanks David!  You're exactly right.  I had that staring me in the face, since (I see now that) req.get().get_cap() returns an any_pointer::Builder.

Troy
Reply all
Reply to author
Forward
0 new messages