Skip to content

Commit f7b3621

Browse files
cBournhonesquealice-i-cecilejanhohenheim
authored andcommitted
Add conversion from DebugName to Cow<'static, str> (#21257)
# Objective There seems to be no way to get the underlying `Cow<'static, str>` from the `DebugName`. This is useful for me to be able to use `DebugName` and have it interop seamlessly with the `metrics` crate: https://docs.rs/metrics/latest/metrics/type.SharedString.html which is the standard why to register/record metrics in rust. Is it possible to include this in 0.17? --------- Co-authored-by: Alice Cecile <[email protected]> Co-authored-by: Jan Hohenheim <[email protected]>
1 parent f5c172e commit f7b3621

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

crates/bevy_utils/src/debug_info.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,26 @@ cfg::alloc! {
132132
Self::owned(value)
133133
}
134134
}
135+
136+
impl From<DebugName> for Cow<'static, str> {
137+
#[cfg_attr(
138+
not(feature = "debug"),
139+
expect(
140+
unused_variables,
141+
reason = "The value will be ignored if the `debug` feature is not enabled"
142+
)
143+
)]
144+
fn from(value: DebugName) -> Self {
145+
#[cfg(feature = "debug")]
146+
{
147+
value.name
148+
}
149+
#[cfg(not(feature = "debug"))]
150+
{
151+
Cow::Borrowed(FEATURE_DISABLED)
152+
}
153+
}
154+
}
135155
}
136156

137157
impl From<&'static str> for DebugName {

0 commit comments

Comments
 (0)