Expand description
§Rialo CLI Representable Derive Macro
This crate provides a procedural macro for deriving the Representable and HumanReadable traits
for structs in the Rialo CLI system.
§Usage
To use this macro, add the following to your struct:
#[derive(Representable)]
#[representable(human_readable = "my_human_readable_fn")]
struct MyStruct {
pub field1: String,
pub field2: u64,
}
fn my_human_readable_fn(data: &MyStruct) -> String {
format!("Field1: {}, Field2: {}", data.field1, data.field2)
}§Attributes
The #[representable] attribute supports the following options:
human_readable = "function_name": Specifies a custom function to use for human-readable output. The function should take a reference to the struct and return aString.
If no human_readable function is specified, the macro defaults to using serde_json::to_string().
§Generated Code
The macro generates implementations for:
Representable: A marker trait for CLI-representable typesHumanReadable: Provides ahuman_readable()method that returns a user-friendly string representation
§Example with Custom Display Function
#[derive(serde::Serialize, Clone, Representable)]
#[representable(human_readable = "balance_display")]
pub struct BalanceResult {
pub amount: f64,
pub currency: String,
}
fn balance_display(result: &BalanceResult) -> String {
format!("Balance: {} {}", result.amount, result.currency)
}Derive Macros§
- Representable
- Derives the
RepresentableandHumanReadabletraits for a struct.