commit d36487e28f7d69d2f48b23f9df038dec3568136d
parent 06c9023e3023a6b94d69912d761e4de2e94db7ec
Author: William Casarin <jb55@jb55.com>
Date: Tue, 10 Dec 2024 15:11:27 -0800
caution: don't crash on unknown keyword
Fixes: 34f0c3b0ce05 ("serialization for DecksCache")
Diffstat:
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/src/storage/decks.rs b/src/storage/decks.rs
@@ -174,13 +174,15 @@ impl MetadataKeyword {
}
impl fmt::Display for MetadataKeyword {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- let name = MetadataKeyword::MAPPING
+ if let Some(name) = MetadataKeyword::MAPPING
.iter()
.find(|(_, keyword)| keyword == self)
.map(|(name, _)| *name)
- .expect("MAPPING is incorrect");
-
- write!(f, "{}", name)
+ {
+ write!(f, "{}", name)
+ } else {
+ write!(f, "UnknownMetadataKeyword")
+ }
}
}
@@ -407,13 +409,15 @@ impl Keyword {
impl fmt::Display for Keyword {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- let name = Keyword::MAPPING
+ if let Some(name) = Keyword::MAPPING
.iter()
.find(|(_, keyword, _)| keyword == self)
.map(|(name, _, _)| *name)
- .expect("MAPPING is incorrect");
-
- write!(f, "{}", name)
+ {
+ write!(f, "{}", name)
+ } else {
+ write!(f, "UnknownKeyword")
+ }
}
}