146 releases (25 breaking)

0.25.3 Apr 2, 2026
0.25.2 Mar 30, 2026
0.25.0 Jan 9, 2026
0.24.0 Dec 24, 2025
0.0.5 Nov 23, 2014

#68 in #encoding

Download history 23185/week @ 2026-03-03 169893/week @ 2026-03-10 118962/week @ 2026-03-17 99032/week @ 2026-03-24 109581/week @ 2026-03-31 130199/week @ 2026-04-07 117798/week @ 2026-04-14 93290/week @ 2026-04-21 63800/week @ 2026-04-28 60377/week @ 2026-05-05 67375/week @ 2026-05-12 62027/week @ 2026-05-19 70953/week @ 2026-05-26 67079/week @ 2026-06-02

277,343 downloads per month
Used in 181 crates (70 directly)

MIT license

175KB
3.5K 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.25" # Note this is a different library than capnp*c*

[build-dependencies]
capnpc = "0.25"

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:

capnp::generated_code!(mod foo_capnp);
capnp::generated_code!(mod bar_capnp);

This will be equivalent to executing the shell command

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

Dependencies