rust-prometheus icon indicating copy to clipboard operation
rust-prometheus copied to clipboard

static-metric/src/builder: Allow non-public label enums

Open mxinden opened this issue 4 years ago • 1 comments

Imagine the following static metric generation:

make_static_metric! {
    label_enum Methods {
        post,
        get,
    }

    struct MyStaticCounterVec: Counter {
        "method" => Methods,
    }
}

This will roughly expand to:

enum Methods {
    post,
    get,
}

use self::prometheus_static_scope_0::MyStaticCounterVec;
mod prometheus_static_scope_0 {
    pub struct MyStaticCounterVec {
        pub post: MyStaticCounterVec2,
        pub get: MyStaticCounterVec2,
    }
}

Rustc would complain that the private type 'Methods' [is] in [the] public interface (error E0446) MyStaticCounterVec.

There is no reason for MyStaticCounterVec to be defined with visibility pub. This commit instead defines MyStaticCounterVec with pub(super) and thus MyStaticCounterVec does not expose the private type Methods.

Signed-off-by: Max Inden [email protected]

mxinden avatar Oct 19 '20 09:10 mxinden

Maybe supplying some tests that will pass compile in this PR but will fail in master would be better!

breezewish avatar Oct 20 '20 05:10 breezewish