improvement: load_cloned returns a result

This commit is contained in:
timokoesters 2019-10-24 10:13:32 +02:00
parent 0a1e12c9ad
commit f1b728b89b
No known key found for this signature in database
GPG Key ID: CD80BE9AAEE78097
3 changed files with 5 additions and 5 deletions

View File

@ -85,9 +85,9 @@ pub fn load<A: Asset + 'static>(specifier: &str) -> Result<Arc<A>, Error> {
}
/// Function used to load assets from the filesystem or the cache and return a clone.
pub fn load_cloned<A: Asset + Clone + 'static>(specifier: &str) -> Option<A> {
let asset: Option<Arc<A>> = load(specifier).ok();
asset.map(|asset| (*asset).clone())
pub fn load_cloned<A: Asset + Clone + 'static>(specifier: &str) -> Result<A, Error> {
let asset = load(specifier);
asset.map(|asset: Arc<A>| (*asset).clone())
}
/// Function used to load essential assets from the filesystem or the cache. It will panic if the asset is not found.

View File

@ -205,7 +205,7 @@ impl Server {
server_settings: &ServerSettings,
) {
// Give no item when an invalid specifier is given
let main = main.and_then(|specifier| assets::load_cloned(&specifier));
let main = main.and_then(|specifier| assets::load_cloned(&specifier).ok());
let spawn_point = state.ecs().read_resource::<SpawnPoint>().0;

View File

@ -98,7 +98,7 @@ impl PlayState for CharSelectionState {
main: self
.char_selection_ui
.character_tool
.and_then(|specifier| assets::load_cloned(&specifier)),
.and_then(|specifier| assets::load_cloned(&specifier).ok()),
alt: None,
},
);