Skip to content

Commit 476862e

Browse files
authored
static-metric/src/parser: Allow not specifying visibility (#351)
When determining whether to parse a struct or an enum the `Parse` implementation for `StaticMetricMacroBodyItem` checks for the tokens `struct` or `enum`. Given that the two can optionally be preceeded by a visibility token (e.g. `pub(crate)`) one needs to peek at both the first and the second token. Signed-off-by: Max Inden <[email protected]>
1 parent 8ce59de commit 476862e

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

static-metric/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog for prometheus-static-metric
22

3+
## 0.5.0 [unreleased]
4+
5+
- Bug fix: Allow not specifying visibility token (e.g. `pub(crate)`) for metric definition.
6+
37
## 0.4.0
48

59
- Misc: Update dependencies (https://github.com/tikv/rust-prometheus/pull/289, https://github.com/tikv/rust-prometheus/pull/311)

static-metric/src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ pub enum StaticMetricMacroBodyItem {
251251

252252
impl Parse for StaticMetricMacroBodyItem {
253253
fn parse(input: ParseStream) -> Result<Self> {
254-
if input.peek2(Token!(struct)) || input.peek2(Token!(struct)) {
254+
if input.peek(Token!(struct)) || input.peek2(Token!(struct)) {
255255
Ok(StaticMetricMacroBodyItem::Metric(input.parse()?))
256256
} else {
257257
Ok(StaticMetricMacroBodyItem::Enum(input.parse()?))

static-metric/tests/metric.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ make_static_metric! {
3737
bar: "bar_name",
3838
},
3939
}
40+
41+
struct NonPubCounterVec: Counter {
42+
"method" => Methods,
43+
}
4044
}
4145

4246
/// Helper method to get a label values of a `Counter`.

0 commit comments

Comments
 (0)