Skip to content

Commit ecaf155

Browse files
committed
Document derived EncodeLabelValue attributes
Signed-off-by: Eric Hodel <[email protected]>
1 parent 688ca66 commit ecaf155

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

derive-encode/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,26 @@ pub fn derive_encode_label_set(input: TokenStream) -> TokenStream {
8888
}
8989

9090
/// Derive `prometheus_client::encoding::EncodeLabelValue`.
91+
///
92+
/// This macro only applies to `enum`s and will panic if you attempt to use it on structs.
93+
///
94+
/// At the enum level you can use `#[prometheus(value_case = "lower")]` or `"upper"` to set the
95+
/// default case of the enum variants.
96+
///
97+
/// ```rust
98+
/// # use prometheus_client::encoding::EncodeLabelValue;
99+
/// #[derive(Clone, Hash, PartialEq, Eq, EncodeLabelValue, Debug)]
100+
/// #[prometheus(value_case = "upper")]
101+
/// enum Method {
102+
/// Get,
103+
/// Put,
104+
/// }
105+
/// ```
106+
///
107+
/// Will encode to label values "GET" and "PUT" in prometheus metrics.
108+
///
109+
/// For variants you can use `#[prometheus(lower)]` or `#[prometheus(upper)]` to set the case for
110+
/// only that variant.
91111
#[proc_macro_derive(EncodeLabelValue, attributes(prometheus))]
92112
pub fn derive_encode_label_value(input: TokenStream) -> TokenStream {
93113
let ast: DeriveInput = syn::parse(input).unwrap();

0 commit comments

Comments
 (0)