Skip to content

Commit

Permalink
*: Feature gate protobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden committed Nov 19, 2022
1 parent 58d2915 commit 93819ed
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
6 changes: 2 additions & 4 deletions Cargo.toml
Expand Up @@ -11,9 +11,8 @@ homepage = "https://github.com/prometheus/client_rust"
documentation = "https://docs.rs/prometheus-client"

[features]
# TODO: Revert
default = ["protobuf"]
protobuf = ["dep:prost", "dep:prost-types", "dep:prost-build", "dep:void"]
default = []
protobuf = ["dep:prost", "dep:prost-types", "dep:prost-build"]

[workspace]
members = ["derive-encode"]
Expand All @@ -25,7 +24,6 @@ parking_lot = "0.12"
prometheus-client-derive-encode = { version = "0.3.0", path = "derive-encode" }
prost = { version = "0.9.0", optional = true }
prost-types = { version = "0.9.0", optional = true }
void = { version = "1.0", optional = true }

[dev-dependencies]
async-std = { version = "1", features = ["attributes"] }
Expand Down
2 changes: 1 addition & 1 deletion derive-encode/Cargo.toml
Expand Up @@ -17,7 +17,7 @@ quote = "1"
syn = "1"

[dev-dependencies]
prometheus-client = { path = "../", all-features = true }
prometheus-client = { path = "../", features = ["protobuf"] }

[lib]
proc-macro = true
17 changes: 17 additions & 0 deletions src/encoding.rs
Expand Up @@ -59,6 +59,7 @@ impl<'a, 'b> From<text::MetricEncoder<'a, 'b>> for MetricEncoder<'a, 'b> {
}
}

#[cfg(feature = "protobuf")]
impl<'a, 'b> From<protobuf::MetricEncoder<'a>> for MetricEncoder<'a, 'b> {
fn from(e: protobuf::MetricEncoder<'a>) -> Self {
Self(MetricEncoderInner::Protobuf(e))
Expand All @@ -69,6 +70,7 @@ macro_rules! for_both_mut {
($self:expr, $inner:ident, $pattern:pat, $fn:expr) => {
match &mut $self.0 {
$inner::Text($pattern) => $fn,
#[cfg(feature = "protobuf")]
$inner::Protobuf($pattern) => $fn,
}
};
Expand All @@ -78,6 +80,7 @@ macro_rules! for_both {
($self:expr, $inner:ident, $pattern:pat, $fn:expr) => {
match $self.0 {
$inner::Text($pattern) => $fn,
#[cfg(feature = "protobuf")]
$inner::Protobuf($pattern) => $fn,
}
};
Expand Down Expand Up @@ -156,9 +159,11 @@ pub struct LabelSetEncoder<'a>(LabelSetEncoderInner<'a>);
#[derive(Debug)]
enum LabelSetEncoderInner<'a> {
Text(text::LabelSetEncoder<'a>),
#[cfg(feature = "protobuf")]
Protobuf(protobuf::LabelSetEncoder<'a>),
}

#[cfg(feature = "protobuf")]
impl<'a> From<protobuf::LabelSetEncoder<'a>> for LabelSetEncoder<'a> {
fn from(e: protobuf::LabelSetEncoder<'a>) -> Self {
Self(LabelSetEncoderInner::Protobuf(e))
Expand All @@ -185,6 +190,7 @@ pub struct LabelEncoder<'a>(LabelEncoderInner<'a>);
#[derive(Debug)]
enum LabelEncoderInner<'a> {
Text(text::LabelEncoder<'a>),
#[cfg(feature = "protobuf")]
Protobuf(protobuf::LabelEncoder<'a>),
}

Expand All @@ -194,6 +200,7 @@ impl<'a> From<text::LabelEncoder<'a>> for LabelEncoder<'a> {
}
}

#[cfg(feature = "protobuf")]
impl<'a> From<protobuf::LabelEncoder<'a>> for LabelEncoder<'a> {
fn from(e: protobuf::LabelEncoder<'a>) -> Self {
Self(LabelEncoderInner::Protobuf(e))
Expand Down Expand Up @@ -225,6 +232,7 @@ pub struct LabelKeyEncoder<'a>(LabelKeyEncoderInner<'a>);
#[derive(Debug)]
enum LabelKeyEncoderInner<'a> {
Text(text::LabelKeyEncoder<'a>),
#[cfg(feature = "protobuf")]
Protobuf(protobuf::LabelKeyEncoder<'a>),
}

Expand All @@ -234,6 +242,7 @@ impl<'a> From<text::LabelKeyEncoder<'a>> for LabelKeyEncoder<'a> {
}
}

#[cfg(feature = "protobuf")]
impl<'a> From<protobuf::LabelKeyEncoder<'a>> for LabelKeyEncoder<'a> {
fn from(e: protobuf::LabelKeyEncoder<'a>) -> Self {
Self(LabelKeyEncoderInner::Protobuf(e))
Expand Down Expand Up @@ -274,6 +283,7 @@ impl<'a> From<text::LabelValueEncoder<'a>> for LabelValueEncoder<'a> {
}
}

#[cfg(feature = "protobuf")]
impl<'a> From<protobuf::LabelValueEncoder<'a>> for LabelValueEncoder<'a> {
fn from(e: protobuf::LabelValueEncoder<'a>) -> Self {
LabelValueEncoder(LabelValueEncoderInner::Protobuf(e))
Expand All @@ -283,6 +293,7 @@ impl<'a> From<protobuf::LabelValueEncoder<'a>> for LabelValueEncoder<'a> {
#[derive(Debug)]
enum LabelValueEncoderInner<'a> {
Text(text::LabelValueEncoder<'a>),
#[cfg(feature = "protobuf")]
Protobuf(protobuf::LabelValueEncoder<'a>),
}

Expand Down Expand Up @@ -420,6 +431,7 @@ pub struct GaugeValueEncoder<'a>(GaugeValueEncoderInner<'a>);
#[derive(Debug)]
enum GaugeValueEncoderInner<'a> {
Text(text::GaugeValueEncoder<'a>),
#[cfg(feature = "protobuf")]
Protobuf(protobuf::GaugeValueEncoder<'a>),
}

Expand All @@ -439,6 +451,7 @@ impl<'a> From<text::GaugeValueEncoder<'a>> for GaugeValueEncoder<'a> {
}
}

#[cfg(feature = "protobuf")]
impl<'a> From<protobuf::GaugeValueEncoder<'a>> for GaugeValueEncoder<'a> {
fn from(e: protobuf::GaugeValueEncoder<'a>) -> Self {
GaugeValueEncoder(GaugeValueEncoderInner::Protobuf(e))
Expand Down Expand Up @@ -470,6 +483,7 @@ pub struct CounterValueEncoder<'a>(CounterValueEncoderInner<'a>);
#[derive(Debug)]
enum CounterValueEncoderInner<'a> {
Text(text::CounterValueEncoder<'a>),
#[cfg(feature = "protobuf")]
Protobuf(protobuf::CounterValueEncoder<'a>),
}

Expand Down Expand Up @@ -507,6 +521,7 @@ impl<'a> From<text::CounterValueEncoder<'a>> for CounterValueEncoder<'a> {
}
}

#[cfg(feature = "protobuf")]
impl<'a> From<protobuf::CounterValueEncoder<'a>> for CounterValueEncoder<'a> {
fn from(e: protobuf::CounterValueEncoder<'a>) -> Self {
CounterValueEncoder(CounterValueEncoderInner::Protobuf(e))
Expand All @@ -520,6 +535,7 @@ pub struct ExemplarValueEncoder<'a>(ExemplarValueEncoderInner<'a>);
#[derive(Debug)]
enum ExemplarValueEncoderInner<'a> {
Text(text::ExemplarValueEncoder<'a>),
#[cfg(feature = "protobuf")]
Protobuf(protobuf::ExemplarValueEncoder<'a>),
}

Expand All @@ -535,6 +551,7 @@ impl<'a> From<text::ExemplarValueEncoder<'a>> for ExemplarValueEncoder<'a> {
}
}

#[cfg(feature = "protobuf")]
impl<'a> From<protobuf::ExemplarValueEncoder<'a>> for ExemplarValueEncoder<'a> {
fn from(e: protobuf::ExemplarValueEncoder<'a>) -> Self {
ExemplarValueEncoder(ExemplarValueEncoderInner::Protobuf(e))
Expand Down

0 comments on commit 93819ed

Please sign in to comment.