Skip to content

Commit

Permalink
Merge branch 'main' into sentry-exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
tobz committed May 5, 2024
2 parents 801cb08 + 3fc0b4f commit 2327b6c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions metrics/src/cow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,20 @@ impl<'a> From<std::borrow::Cow<'a, str>> for Cow<'a, str> {
}
}

impl<'a, T: Cowable> From<Cow<'a, T>> for std::borrow::Cow<'a, T> {
#[inline]
fn from(value: Cow<'a, T>) -> Self {
match value.metadata.kind() {
Kind::Owned | Kind::Shared => Self::Owned(value.into_owned()),
Kind::Borrowed => {
// SAFETY: We know the contained data is borrowed from 'a, we're simply
// restoring the original immutable reference and returning a copy of it.
Self::Borrowed(unsafe { &*T::borrowed_from_parts(value.ptr, &value.metadata) })
}
}
}
}

impl From<String> for Cow<'_, str> {
#[inline]
fn from(s: String) -> Self {
Expand Down

0 comments on commit 2327b6c

Please sign in to comment.