Skip to main content

FromCapnp

Derive Macro FromCapnp 

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

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

Generates an implementation of FromCapnp trait that reads struct fields from a Cap’n Proto reader.

§Attributes

  • #[capnp(path::to::schema)] - Required. Specifies the Cap’n Proto schema path.
  • #[capnp(skip)] on field - Skip this field, use Default::default().
  • #[capnp(rename = "other_name")] on field - Use a different name for the getter.
  • #[capnp(optional)] on field - Field is Option, handle missing gracefully.

§Example

ⓘ
#[derive(FromCapnp)]
#[capnp(registry_capnp::health_status)]
pub struct HealthStatus {
    pub status: String,
    pub repository_count: u32,
    #[capnp(optional)]
    pub message: Option<String>,
}