-
Notifications
You must be signed in to change notification settings - Fork 492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[semantic-conventions] provide constants for literal string values to support use as match conditions #685
Comments
Could consider having both constants, you should be able to use Key::as_str as a workaround to check equality as well. |
Right now I'm using |
I'm confused by the issue description: first, there is no impl PartialEq<str> for Key {
fn eq(&self, other: &str) -> bool {
self.0.as_ref() == other
}
}
fn foo() {
match Key::new("foo") {
"foo" => true,
_ => false,
};
} still errors with error[E0308]: mismatched types
--> opentelemetry/src/common.rs:109:9
|
108 | match Key::new("foo") {
| --------------- this expression has type `Key`
109 | "foo" => true,
| ^^^^^ expected struct `Key`, found `&str` Still, I don't understand your statement that fn foo() {
match Key::new("foo").as_str() {
"foo" => true,
_ => false,
};
} |
not sure what you mean by there being no from resource.rs: use opentelemetry::Key;
...
pub const CLOUD_PROVIDER: Key = Key::from_static_str("cloud.provider");
... I'm not looking to match the match Key::new(string_from_external_source) {
resource::SERVICE_VERSION => ...,
resource::SERVICE_NAME => ...
} It doesn't matter if |
@KallDrexx weren't you working on stuff related to this? |
Isn't this #1334? |
Yes it seems so 👍 |
Currently, the
Key
values in the semantic conventions crate cannot be used as conditions inside of a match expression because the innerCow
does not derive PartialEq and Eq.While it would be nice to be able to use the
Key
s directly as match conditions, I appreciate that moving away from aCow
based implementation isn't feasible.What I think would be a workable alternative would be to have constants not only for the
Key
s, but for the the literal strings used to construct theKey
s. With those, the string constants could be used as match conditions even if theKey
s cannot.The text was updated successfully, but these errors were encountered: