Skip to main content

Representable

Derive Macro Representable 

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

Derives the Representable and HumanReadable traits for a struct.

This macro automatically implements:

  • Representable: A marker trait indicating the type can be represented in CLI output
  • HumanReadable: Provides a human_readable() method for user-friendly string representation

§Attributes

§#[representable(human_readable = "function_name")]

Specifies a custom function to use for human-readable output. The function should:

  • Take a reference to the struct (&Self)
  • Return a String
  • Be defined in the same module as the struct

§Examples

With a custom human-readable function:

#[derive(Representable)]
#[representable(human_readable = "custom_display")]
struct MyData {
    value: u64,
}

fn custom_display(data: &MyData) -> String {
    format!("Value: {}", data.value)
}

Without specifying a function (defaults to JSON):

#[derive(Representable)]
struct MyData {
    value: u64,
}
// Will use serde_json::to_string(self) by default