rafx_assets/assets/
asset_manager_render_resource.rs1use super::AssetManager;
2use rafx_base::memory::force_to_static_lifetime;
3use std::ops::Deref;
4use std::sync::Arc;
5
6#[derive(Default)]
9pub struct AssetManagerRenderResource(Option<Arc<&'static AssetManager>>);
10
11impl AssetManagerRenderResource {
12 pub unsafe fn begin_extract(
14 &mut self,
15 asset_manager: &AssetManager,
16 ) {
17 assert!(self.0.is_none());
18 self.0 = Some(Arc::new(force_to_static_lifetime(asset_manager)));
19 }
20
21 pub fn end_extract(&mut self) {
23 self.0
24 .take()
25 .to_owned()
26 .expect("Reference to AssetManager is still in use");
27 }
28
29 pub fn extract_ref(&self) -> AssetManagerExtractRef {
32 AssetManagerExtractRef(self.0.as_ref().unwrap().clone())
33 }
34}
35
36#[derive(Clone)]
38pub struct AssetManagerExtractRef(Arc<&'static AssetManager>);
39
40impl Deref for AssetManagerExtractRef {
41 type Target = AssetManager;
42
43 fn deref(&self) -> &Self::Target {
44 &*self.0
45 }
46}