Skip to content

Commit dfb904c

Browse files
authored
Use irrefutable pattern matching to remove expect usage (#24043)
# Objective Reduce usage of `expect` in the codebase. ## Solution Use irrefutable pattern matching to statically guarantee the `Ok` variant.
1 parent 9c13183 commit dfb904c

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

crates/bevy_asset/src/loader.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use bevy_ecs::{error::BevyError, world::World};
1212
use bevy_platform::collections::{hash_map::Entry, HashMap, HashSet};
1313
use bevy_reflect::TypePath;
1414
use bevy_tasks::{BoxedFuture, ConditionalSendFuture};
15-
use core::any::{Any, TypeId};
15+
use core::{
16+
any::{Any, TypeId},
17+
convert::Infallible,
18+
};
1619
use downcast_rs::{impl_downcast, Downcast};
1720
use ron::error::SpannedError;
1821
use serde::{Deserialize, Serialize};
@@ -475,8 +478,8 @@ impl<'a> LoadContext<'a> {
475478
label: impl Into<CowArc<'static, str>>,
476479
asset: A,
477480
) -> Handle<A> {
478-
self.labeled_asset_scope(label, |_| Ok::<_, ()>(asset))
479-
.expect("the closure returns Ok")
481+
let Ok(handle) = self.labeled_asset_scope(label, |_| Ok::<_, Infallible>(asset));
482+
handle
480483
}
481484

482485
/// Add a [`LoadedAsset`] that is a "labeled sub asset" of the root path of this load context.

0 commit comments

Comments
 (0)