capnproto / capnpc-rust

Cap'n Proto code generation for Rust
76 stars 26 forks source link

Making type IDs accessible from Rust code #2

Closed ghost closed 9 years ago

ghost commented 9 years ago

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 the Reader and Builder both implement the HasTypeId trait defining a type_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 the HasTypeId trait

This pull request requires the HasTypeId trait in the runtime library.

dwrensha commented 9 years ago

Looks good! I just have a few nitpicks, as discussed in my other comments.

dwrensha commented 9 years ago

I went ahead and merged your branch that had the private inner module. Thanks!

ghost commented 9 years ago

Oops, Sorry! Looks like I took too long to do the last fixes! vaelden/capnpc-rust@2eed1ce81ac7696f0c5b639aea9aba19e5acc602 should make the necessary changes to remove unused imports and make TYPE_ID accessible for groups.

dwrensha commented 9 years ago

No worries! I've just merged that commit in too.