-
Notifications
You must be signed in to change notification settings - Fork 26
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
Making type IDs accessible from Rust code #2
Conversation
@@ -1286,6 +1320,7 @@ fn generate_node(node_map : &collections::hash_map::HashMap<u64, schema_capnp::n | |||
Line("use capnp::capability::{ClientHook, FromClientHook, FromServer, Request, ServerHook};".to_string())); | |||
mod_interior.push(Line("use capnp::capability;".to_string())); | |||
mod_interior.push(BlankLine); | |||
mod_interior.push(Line(format!("pub const INTERFACE_ID: u64 = {:#x};", node_id))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this ought to be called TYPE_ID
as well. That would be more consistent with the C++ version (see the definition of CAPNP_DECLARE_INTERFACE_HEADER
in generated_header_support.h). Do you have a reason to prefer INTERFACE_ID
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well I thought INTERFACE_ID would be a little bit more explicit, but I'm not really attached to it ...
Looks good! I just have a few nitpicks, as discussed in my other comments. |
I went ahead and merged your branch that had the private inner module. Thanks! |
Oops, Sorry! Looks like I took too long to do the last fixes! |
No worries! I've just merged that commit in too. |
These patches should allow the use of Capn'Proto type ids from Rust code.
For a Capn'Proto struct, it declares a
const TYPE_ID: u64
in the module defining the struct, and theReader
andBuilder
both implement theHasTypeId
trait defining atype_id(_ : Option<Self>)
function (no better way to call it before UFCS).For an enum, it only makes the enum implement the
HasTypeId
trait.For an interface, it declare a
const INTERFACE_ID: u64
in the module defining the interface, and the Client implements theHasTypeId
traitThis pull request requires the HasTypeId trait in the runtime library.