Skip to content

Trait for a "label" #297

Open
Open
@Palmik

Description

@Palmik

I have some type (e.g. struct), that I would like to derive label(s) from, e.g.

struct X {
   abc: u64,
   def: &'static str
}
let x = X { abc: 123, def: "a" };
increment_counter!("foo", x);

Could be equivalent to:

increment_counter!("foo", "x_abc" => 123, "x_def" => "a");

I tried using IntoLabels, unfortunately it does not compose:

increment_counter!("foo", x, y); // Does not work
increment_counter!("foo", x, "x" => "y"); // Does not work

What are your thoughts on extending the macro syntax?

Perhaps another alternative would be to define a macro that would expand values of X into key => value pairs, but I was not able to come up with that -- this would already help and be more efficient (but less ergonomic) as it would also avoid the IntoLabels Vec allocation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-coreComponent: core functionality such as traits, etc.C-macrosComponent: macros.E-complexEffort: complex.T-ergonomicsType: ergonomics.T-experimentType: experiment.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions