rafx_assets/
hydrate_impl.rs1pub use hydrate_loader::artifact_storage::{DynArtifactLoader, UpdateArtifactResult};
2pub use hydrate_loader::ArtifactManager as AssetResource;
3
4use crate::load_queue_hydrate::RafxGenericLoadEventHandler;
5use crate::resource_loader::RafxLoadEventHandler;
6use crossbeam_channel::Sender;
7use hydrate_base::handle::LoaderInfoProvider;
8use hydrate_base::handle::RefOp;
9use hydrate_base::handle::SerdeContext;
10use hydrate_base::LoadHandle;
11use hydrate_loader::storage::ArtifactLoadOp;
12use std::error::Error;
13use type_uuid::TypeUuid;
14
15pub struct RafxResourceAssetLoader<AssetDataT, AssetT>(
19 pub RafxGenericLoadEventHandler<AssetDataT, AssetT>,
20)
21where
22 AssetDataT: for<'a> serde::Deserialize<'a> + 'static + Send,
23 AssetT: TypeUuid + 'static + Send;
24
25impl<AssetDataT, AssetT> DynArtifactLoader<AssetT> for RafxResourceAssetLoader<AssetDataT, AssetT>
26where
27 AssetDataT: for<'a> serde::Deserialize<'a> + 'static + Send,
28 AssetT: TypeUuid + 'static + Send,
29{
30 fn load_artifact(
31 &mut self,
32 refop_sender: &Sender<RefOp>,
33 loader_info: &dyn LoaderInfoProvider,
34 data: &[u8],
35 load_handle: LoadHandle,
36 load_op: ArtifactLoadOp,
37 ) -> Result<UpdateArtifactResult<AssetT>, Box<dyn Error + Send>> {
38 let asset = SerdeContext::with(loader_info, refop_sender.clone(), || {
40 bincode::deserialize::<AssetDataT>(data)
41 .map_err(|x| -> Box<dyn Error + Send + 'static> { Box::new(x) })
43 })?;
44
45 let result = self.0.update_asset(load_handle, load_op, asset);
46 Ok(UpdateArtifactResult::AsyncResult(result.result_rx))
47 }
48
49 fn commit_artifact(
50 &mut self,
51 handle: LoadHandle,
52 ) {
53 self.0.commit_asset_version(handle);
54 }
55
56 fn free_artifact(
57 &mut self,
58 handle: LoadHandle,
59 ) {
60 self.0.free(handle);
61 }
62}