Skip to content

Commit 8adbd99

Browse files
committed
Simplify the asset_saving example using get_labeled_by_id.
1 parent d47863a commit 8adbd99

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

examples/asset/asset_saving.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,13 @@ impl AssetSaver for ManyBoxesSaver {
176176
.boxes
177177
.iter()
178178
.map(|handle| {
179-
// TODO: We should have a better to get the asset for a subasset handle.
180-
let label = handle
181-
.path()
182-
.and_then(|path| path.label())
183-
.ok_or_else(|| format!("Failed to get label for handle {handle:?}"))?;
184179
asset
185-
.get_labeled::<OneBox>(label)
186-
.map(|subasset| subasset.get().clone())
187-
.ok_or_else(|| format!("Failed to find labeled asset for label {label}"))
180+
.get_labeled_by_id::<OneBox>(handle)
181+
.unwrap()
182+
.get()
183+
.clone()
188184
})
189-
.collect::<Result<Vec<_>, _>>()?;
185+
.collect();
190186

191187
// Note: serializing to string isn't ideal since we can't do a streaming write, but this is
192188
// fine for an example.

0 commit comments

Comments
 (0)