Skip to content

Commit 0b0077d

Browse files
committed
Return owned string from tag canonicalization.
1 parent 67bb42b commit 0b0077d

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/tag.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ fn collect_tags(tags: &[Tag]) -> Tags {
4848
tags.iter()
4949
.map(|tag| {
5050
let key = match tag.std_key {
51-
Some(std_key) => std_key.canonical_tag_key().to_string(),
52-
None => tag.key.canonical_tag_key().to_string(),
51+
Some(std_key) => std_key.canonical_tag_key(),
52+
None => tag.key.canonical_tag_key(),
5353
};
5454
(key, tag.value.to_string())
5555
})

src/tag_key.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ use std::sync::LazyLock;
33
use symphonia::core::meta::StandardTagKey;
44

55
pub trait CanonicalTagKey {
6-
fn canonical_tag_key(&self) -> &str;
6+
fn canonical_tag_key(&self) -> String;
77
}
88

99
static NONSTANDARD_TAG_MAPPING: LazyLock<HashMap<String, String>> = LazyLock::new(|| {
1010
serde_json::from_str(include_str!("tag_key_mapping.json"))
1111
.expect("Failed to parse tag mapping.")
1212
});
1313
impl CanonicalTagKey for str {
14-
fn canonical_tag_key(&self) -> &str {
14+
fn canonical_tag_key(&self) -> String {
1515
NONSTANDARD_TAG_MAPPING
1616
.get(self)
17-
.map_or(self, |s| s.as_str())
17+
.map_or(self.to_string(), |s| s.clone())
1818
}
1919
}
2020

2121
impl CanonicalTagKey for StandardTagKey {
22-
fn canonical_tag_key(&self) -> &str {
22+
fn canonical_tag_key(&self) -> String {
2323
match self {
2424
StandardTagKey::AcoustidFingerprint => "AcoustidFingerprint",
2525
StandardTagKey::AcoustidId => "AcoustidId",
@@ -133,5 +133,6 @@ impl CanonicalTagKey for StandardTagKey {
133133
StandardTagKey::Version => "Version",
134134
StandardTagKey::Writer => "Writer",
135135
}
136+
.to_string()
136137
}
137138
}

0 commit comments

Comments
 (0)