Skip to main content

ToCapnp

Derive Macro ToCapnp 

Source
#[derive(ToCapnp)]
{
    // Attributes available to this derive:
    #[capnp]
}
Expand description

Derive macro for serializing Rust types to Cap’n Proto.

Generates an implementation of ToCapnp trait that writes struct fields to a Cap’n Proto builder.

§Attributes

  • #[capnp(path::to::schema)] - Required. Specifies the Cap’n Proto schema path.
  • #[capnp(skip)] on field - Skip this field during serialization.
  • #[capnp(rename = "other_name")] on field - Use a different name for the setter.

§Example

ⓘ
#[derive(ToCapnp)]
#[capnp(registry_capnp::clone_request)]
pub struct CloneRequest {
    pub url: String,
    pub name: String,
    pub shallow: bool,
    #[capnp(rename = "maxDepth")]
    pub depth: u32,
}