async fn load_async<'a, P: Into<AssetPath<'a>>>(
        &self,
        path: P,
        force: bool,
    ) -> Result<AssetPathId, AssetServerError> {
        let asset_path: AssetPath = path.into();
        let asset_loader = self.get_path_asset_loader(asset_path.path())?;
        let asset_path_id: AssetPathId = asset_path.get_id();

        // load metadata and update source info. this is done in a scope to ensure we release the locks before loading
        let version = {
            let mut asset_sources = self.server.asset_sources.write();
            let source_info = match asset_sources.entry(asset_path_id.source_path_id()) {
                Entry::Occupied(entry) => entry.into_mut(),
                Entry::Vacant(entry) => entry.insert(SourceInfo {
                    asset_types: Default::default(),
                    committed_assets: Default::default(),
                    load_state: LoadState::NotLoaded,
                    meta: None,
                    path: asset_path.path().to_owned(),
                    version: 0,
                }),
            };

            // if asset is already loaded (or is loading), don't load again
            if !force
                && source_info
                    .committed_assets
                    .contains(&asset_path_id.label_id())
            {
                return Ok(asset_path_id);
            }

            source_info.load_state = LoadState::Loading;
            source_info.committed_assets.clear();
            source_info.version += 1;
            source_info.meta = None;
            source_info.version
        };

        // load the asset bytes
        let bytes = self.server.asset_io.load_path(asset_path.path()).await?;

        // load the asset source using the corresponding AssetLoader
        let mut load_context = LoadContext::new(
            asset_path.path(),
            &self.server.asset_ref_counter.channel,
            &*self.server.asset_io,
            version,
        );
        asset_loader
            .load(&bytes, &mut load_context)
            .await
            .map_err(AssetServerError::AssetLoaderError)?;

        // if version has changed since we loaded and grabbed a lock, return. theres is a newer version being loaded
        let mut asset_sources = self.server.asset_sources.write();
        let source_info = asset_sources
            .get_mut(&asset_path_id.source_path_id())
            .expect("`AssetSource` should exist at this point.");
        if version != source_info.version {
            return Ok(asset_path_id);
        }

        // if all assets have been committed already (aka there were 0), set state to "Loaded"
        if source_info.is_loaded() {
            source_info.load_state = LoadState::Loaded;
        }

        // reset relevant SourceInfo fields
        source_info.committed_assets.clear();
        // TODO: queue free old assets
        source_info.asset_types.clear();

        source_info.meta = Some(SourceMeta {
            assets: load_context.get_asset_metas(),
        });

        // load asset dependencies and prepare asset type hashmap
        for (label, loaded_asset) in load_context.labeled_assets.iter_mut() {
            let label_id = LabelId::from(label.as_ref().map(|label| label.as_str()));
            let type_uuid = loaded_asset.value.as_ref().unwrap().type_uuid();
            source_info.asset_types.insert(label_id, type_uuid);
            for dependency in loaded_asset.dependencies.iter() {
                self.load_untyped(dependency.clone());
            }
        }

        self.server
            .asset_io
            .watch_path_for_changes(asset_path.path())
            .unwrap();
        self.create_assets_in_load_context(&mut load_context);
        Ok(asset_path_id)
    }
// TODO: properly set failed LoadState in all failure cases
properly set failed LoadState in all failure cases
properly set failed LoadState in all failure cases
async fn load_async<'a, P: Into<AssetPath<'a>>>(
        &self,
        path: P,
        force: bool,
    ) -> Result<AssetPathId, AssetServerError> {
        let asset_path: AssetPath = path.into();
        let asset_loader = self.get_path_asset_loader(asset_path.path())?;
        let asset_path_id: AssetPathId = asset_path.get_id();
        // load metadata and update source info. this is done in a scope to ensure we release the locks before loading
        let version = {
            let mut asset_sources = self.server.asset_sources.write();
            let source_info = match asset_sources.entry(asset_path_id.source_path_id()) {
                Entry::Occupied(entry) => entry.into_mut(),
                Entry::Vacant(entry) => entry.insert(SourceInfo {
                    asset_types: Default::default(),
                    committed_assets: Default::default(),
                    load_state: LoadState::NotLoaded,
                    meta: None,
                    path: asset_path.path().to_owned(),
                    version: 0,
                }),
            };
            // if asset is already loaded (or is loading), don't load again
            if !force
                && source_info
                    .committed_assets
                    .contains(&asset_path_id.label_id())
            {
                return Ok(asset_path_id);
            }
            source_info.load_state = LoadState::Loading;
            source_info.committed_assets.clear();
            source_info.version += 1;
            source_info.meta = None;
            source_info.version
        };
        // load the asset bytes
        let bytes = self.server.asset_io.load_path(asset_path.path()).await?;
        // load the asset source using the corresponding AssetLoader
        let mut load_context = LoadContext::new(
            asset_path.path(),
            &self.server.asset_ref_counter.channel,
            &*self.server.asset_io,
            version,
        );
        asset_loader
            .load(&bytes, &mut load_context)
            .await
            .map_err(AssetServerError::AssetLoaderError)?;
        // if version has changed since we loaded and grabbed a lock, return. theres is a newer version being loaded
        let mut asset_sources = self.server.asset_sources.write();
        let source_info = asset_sources
            .get_mut(&asset_path_id.source_path_id())
            .expect("`AssetSource` should exist at this point.");
        if version != source_info.version {
            return Ok(asset_path_id);
        }
        // if all assets have been committed already (aka there were 0), set state to "Loaded"
        if source_info.is_loaded() {
            source_info.load_state = LoadState::Loaded;
        }
        // reset relevant SourceInfo fields
        source_info.committed_assets.clear();
        // TODO: queue free old assets
        source_info.asset_types.clear();
        source_info.meta = Some(SourceMeta {
            assets: load_context.get_asset_metas(),
        });
        // load asset dependencies and prepare asset type hashmap
        for (label, loaded_asset) in load_context.labeled_assets.iter_mut() {
            let label_id = LabelId::from(label.as_ref().map(|label| label.as_str()));
            let type_uuid = loaded_asset.value.as_ref().unwrap().type_uuid();
            source_info.asset_types.insert(label_id, type_uuid);
            for dependency in loaded_asset.dependencies.iter() {
                self.load_untyped(dependency.clone());
            }
        }
        self.server
            .asset_io
            .watch_path_for_changes(asset_path.path())
            .unwrap();
        self.create_assets_in_load_context(&mut load_context);
        Ok(asset_path_id)
    }
async fn load_async < ' a , P : Into < AssetPath < ' a > > > ( & self , path : P , force : bool , ) -> Result < AssetPathId , AssetServerError > { let asset_path : AssetPath = path . into ( ) ; let asset_loader = self . get_path_asset_loader ( asset_path . path ( ) ) ? ; let asset_path_id : AssetPathId = asset_path . get_id ( ) ; // load metadata and update source info. this is done in a scope to ensure we release the locks before loading let version = { let mut asset_sources = self . server . asset_sources . write ( ) ; let source_info = match asset_sources . entry ( asset_path_id . source_path_id ( ) ) { Entry :: Occupied ( entry ) => entry . into_mut ( ) , Entry :: Vacant ( entry ) => entry . insert ( SourceInfo { asset_types : Default :: default ( ) , committed_assets : Default :: default ( ) , load_state : LoadState :: NotLoaded , meta : None , path : asset_path . path ( ) . to_owned ( ) , version : 0 , } ) , } ; // if asset is already loaded (or is loading), don't load again if ! force && source_info . committed_assets . contains ( & asset_path_id . label_id ( ) ) { return Ok ( asset_path_id ) ; } source_info . load_state = LoadState :: Loading ; source_info . committed_assets . clear ( ) ; source_info . version += 1 ; source_info . meta = None ; source_info . version } ; // load the asset bytes let bytes = self . server . asset_io . load_path ( asset_path . path ( ) ) . await ? ; // load the asset source using the corresponding AssetLoader let mut load_context = LoadContext :: new ( asset_path . path ( ) , & self . server . asset_ref_counter . channel , & * self . server . asset_io , version , ) ; asset_loader . load ( & bytes , & mut load_context ) . await . map_err ( AssetServerError :: AssetLoaderError ) ? ; // if version has changed since we loaded and grabbed a lock, return. theres is a newer version being loaded let mut asset_sources = self . server . asset_sources . write ( ) ; let source_info = asset_sources . get_mut ( & asset_path_id . source_path_id ( ) ) . expect ( " " ) ; if version != source_info . version { return Ok ( asset_path_id ) ; } // if all assets have been committed already (aka there were 0), set state to "Loaded" if source_info . is_loaded ( ) { source_info . load_state = LoadState :: Loaded ; } // reset relevant SourceInfo fields source_info . committed_assets . clear ( ) ; // TODO: queue free old assets source_info . asset_types . clear ( ) ; source_info . meta = Some ( SourceMeta { assets : load_context . get_asset_metas ( ) , } ) ; // load asset dependencies and prepare asset type hashmap for ( label , loaded_asset ) in load_context . labeled_assets . iter_mut ( ) { let label_id = LabelId :: from ( label . as_ref ( ) . map ( | label | label . as_str ( ) ) ) ; let type_uuid = loaded_asset . value . as_ref ( ) . unwrap ( ) . type_uuid ( ) ; source_info . asset_types . insert ( label_id , type_uuid ) ; for dependency in loaded_asset . dependencies . iter ( ) { self . load_untyped ( dependency . clone ( ) ) ; } } self . server . asset_io . watch_path_for_changes ( asset_path . path ( ) ) . unwrap ( ) ; self . create_assets_in_load_context ( & mut load_context ) ; Ok ( asset_path_id ) }
TODO: properly set failed LoadState in all failure cases
TODO : properly set failed LoadState in all failure cases
&self
path
P
force
bool
&self
path
P
force
bool