#[derive(ProfileOp)]
{
// Attributes available to this derive:
#[category]
}
Expand description
Derives the Operation
trait for enums, automatically generating category implementations.
This macro generates unique category structs for each distinct category name found in the
enum variants, and implements the Operation
trait to return the appropriate category
for each variant.
§Attributes
The macro supports the #[category(...)]
attribute on enum variants with the following parameters:
name
: The name of the category (optional, defaults to variant name)description
: A description of the category (optional, defaults to category name)
§Important Behavior
When multiple variants use the same category name:
- Only one category struct is generated per unique category name
- The first
description
encountered for a category name is used - Subsequent descriptions for the same category name are ignored
§Example
ⓘ
use quantum_pulse::{ProfileOp, Operation};
#[derive(Debug, ProfileOp)]
enum MyOperation {
// Category with both name and description
#[category(name = "IO", description = "Input/Output operations")]
ReadFile,
// Same category, description is ignored (first one wins)
#[category(name = "IO", description = "This description is ignored")]
WriteFile,
// Category with only name (description defaults to name)
#[category(name = "Network")]
HttpRequest,
// No category attribute (uses variant name as category)
Compute,
// Supports enum variants with data
#[category(name = "Database")]
Query(String),
// Supports enum variants with named fields
#[category(name = "Cache")]
CacheOp { key: String, ttl: u64 },
}
§Generated Code
For each unique category, the macro generates:
- A hidden struct implementing the
Category
trait - An implementation of
Operation::get_category()
that returns the appropriate category
§Panics
- If applied to anything other than an enum
- If the category attribute parsing fails