Skip to main content

GraphValue

Derive Macro GraphValue 

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

Derive macro for converting between Rust types and Value.

§Structs

Structs are converted to Value::Record with field names as keys.

#[derive(GraphValue)]
struct Person {
    name: String,
    age: i64,
}

§Enums

Enums are converted to Value::Variant with the variant index as tag.

#[derive(GraphValue)]
enum Shape {
    Circle(f64),           // tag 0, payload = radius
    Rectangle(f64, f64),   // tag 1, payload = tuple(width, height)
    Point,                 // tag 2, no payload
}

§Attributes

  • #[graph(crate = "path")] - Specify the crate path (default: packr_abi)
  • #[graph(rename = "name")] - Use a different name for field/variant
  • #[graph(tag = N)] - Use explicit tag number for variant