Skip to content

Commit

Permalink
Avoid unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Feb 7, 2025
1 parent e9b18e4 commit d876106
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/structured_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ impl StructuredMetadata {
let raw = minicbor::decode::<StructuredMetadataRaw>(cbor).ok()?;

Some(StructuredMetadata {
// todo: don't unwrap
gallery: raw.gallery.map(|gallery| {
gallery
.iter()
.map(|item| InscriptionId::from_value(item).unwrap())
.collect()
gallery: raw.gallery.and_then(|gallery| {
let mut items = Vec::new();

for item in gallery {
if let Some(item) = InscriptionId::from_value(&item) {
items.push(item);
} else {
return None;
}
}

Some(items)
}),
})
}
Expand Down

0 comments on commit d876106

Please sign in to comment.