130 releases

0.20.1 Nov 15, 2024
0.19.0 Jan 14, 2024
0.18.0 Sep 4, 2023
0.17.2 Jun 26, 2023
0.0.5 Nov 23, 2014

#58 in Database interfaces

Download history 46379/week @ 2024-12-01 45934/week @ 2024-12-08 43995/week @ 2024-12-15 11567/week @ 2024-12-22 16657/week @ 2024-12-29 41282/week @ 2025-01-05 46570/week @ 2025-01-12 41729/week @ 2025-01-19 45605/week @ 2025-01-26 48530/week @ 2025-02-02 52941/week @ 2025-02-09 48497/week @ 2025-02-16 55345/week @ 2025-02-23 58511/week @ 2025-03-02 63061/week @ 2025-03-09 57575/week @ 2025-03-16

236,892 downloads per month
Used in 81 crates (36 directly)

MIT license

1.5MB
30K SLoC

Cap'n Proto code generation for Rust

crates.io

documentation

The generated code depends on the capnproto-rust runtime library.

Code generation can be customized through the annotations defined in rust.capnp.


lib.rs:

Cap'n Proto Schema Compiler Plugin Library

This library allows you to do Cap'n Proto code generation within a Cargo build. You still need the capnp binary (implemented in C++). (If you use a package manager, try looking for a package called capnproto.)

In your Cargo.toml:

[dependencies]
capnp = "0.20" # Note this is a different library than capnp*c*

[build-dependencies]
capnpc = "0.20"

In your build.rs:

fn main() {
    capnpc::CompilerCommand::new()
        .src_prefix("schema")
        .file("schema/foo.capnp")
        .file("schema/bar.capnp")
        .run().expect("schema compiler command");
}

In your lib.rs:

mod foo_capnp {
    include!(concat!(env!("OUT_DIR"), "/foo_capnp.rs"));
}

mod bar_capnp {
    include!(concat!(env!("OUT_DIR"), "/bar_capnp.rs"));
}

This will be equivalent to executing the shell command

  capnp compile -orust:$OUT_DIR --src-prefix=schema schema/foo.capnp schema/bar.capnp

Dependencies