capnproto-rust
capnproto-rust copied to clipboard
Please improve getting started instructions -- `include!`
The current getting started text from https://crates.io/crates/capnp-rpc would benefit from additional clarity in the following section...
and you can include the generated code in your project like this:
pub mod foo_capnp {
include!(concat!(env!("OUT_DIR"), "/foo_capnp.rs"));
}
My questions are:
- Where exactly does
mod foo_capnpbelong? - How is the path for "foo_capnp.rs" generated? I'm digging around looking for it in my 'target' directory.
Ok, I see that:
- the
include!code belongs in the top-level "lib.rs" - the outputted Rust files have the same path used to read the .capnp files (except they are under "target/.../.../out" instead)
So, if "build.rs" includes:
fn main() {
::capnpc::CompilerCommand::new().file("src/capnp/foo.capnp").run().unwrap();
}
then "lib.rs" should contain:
pub mod foo_capnp {
include!(concat!(env!("OUT_DIR"), "/src/capnp/foo_capnp.rs"));
}
I think the README would benefit by having these details. Would anyone else agree?
There's some documentation about this here: https://github.com/capnproto/capnproto-rust/blob/96f2f7894fbbf55e741c39b183a824e27ddbcc3e/capnpc/src/lib.rs
I agree that more/better documentation would be good. Perhaps the best place to discuss how to include!() would be here: https://github.com/capnproto/capnproto-rust/blob/96f2f7894fbbf55e741c39b183a824e27ddbcc3e/capnp/src/lib.rs
as then it would be at the top of the first page that people see when clicking on the documentation link in the readme: https://docs.capnproto-rust.org/capnp/