Closed jpds closed 5 months ago
Off the top of my head... did you try borrowing the map (i.e. &target.labels.expect(...)
? That would get you the &T
which should then hopefully allow the implementation of IntoLabels
on T: IntoIterator<Item = Into<Label>>
to kick in.
That did work! But then triggers a:
error[E0277]: the trait bound `Label: From<(&std::string::String, &std::string::String)>` is not satisfied
--> src/main.rs:43:52
|
43 | ...et gauge = gauge!(target.metric, &target.labels.expect("Should have gotten a BTreeMap here")).set(/* Fake loc...
| -----------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| | |
| | the trait `From<(&std::string::String, &std::string::String)>` is not implemented for `Label`
| required by a bound introduced by this call
|
= help: the trait `From<&(K, V)>` is implemented for `Label`
= note: required for `(&std::string::String, &std::string::String)` to implement `Into<Label>`
= note: required for `&BTreeMap<std::string::String, std::string::String>` to implement `IntoLabels`
note: required by a bound in `metrics::Key::from_parts`
--> /home/username/.cargo/registry/src/index.crates.io-6f17d22bba15001f/metrics-0.22.3/src/key.rs:83:12
|
80 | pub fn from_parts<N, L>(name: N, labels: L) -> Self
| ---------- required by a bound in this associated function
...
83 | L: IntoLabels,
| ^^^^^^^^^^ required by this bound in `Key::from_parts`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `example` (bin "example") due to previous error
Ah drats, yeah: we only have Into<Label>
for &(K, V)
.
We could probably add another impl for (&K, &V)
.
I'm trying to use this library along with
serde_yaml
to create an exporter which will read a YAML file with targets and then polls those for data.Here's an example YAML file:
And then leverages code which then looks like this:
However, this fails because:
I don't know of any other way of representing the
labels
YAML field - so could this BTreeMap support be added?