-
Notifications
You must be signed in to change notification settings - Fork 675
feat(api): add StringValue::from_static_str #3540
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -259,6 +259,20 @@ impl AsRef<str> for StringValue { | |
| } | ||
|
|
||
| impl StringValue { | ||
| /// Create a new const `StringValue`. | ||
| /// | ||
| /// This is useful for making static label values: | ||
| /// ```rust | ||
| /// # use opentelemetry::{StringValue, KeyValue, Key, Value}; | ||
| /// let labels = &[KeyValue::new( | ||
| /// Key::from_static_str("key"), | ||
| /// StringValue::from_static_str("value"), | ||
| /// )]; | ||
| /// ``` | ||
| pub const fn from_static_str(value: &'static str) -> Self { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add a small doctest showing the actual const use case here?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, we can't make a KeyValue at compile time with the current initializer. I changed the example. |
||
| StringValue(OtelString::Static(value)) | ||
| } | ||
|
|
||
| /// Returns a string slice to this value | ||
| pub fn as_str(&self) -> &str { | ||
| self.0.as_str() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let labels = &[KeyValue::new("key", "value")];
^ couldn't we already this today?