use super::AssetManager;
use rafx_base::memory::force_to_static_lifetime;
use std::ops::Deref;
use std::sync::Arc;
#[derive(Default)]
pub struct AssetManagerRenderResource(Option<Arc<&'static AssetManager>>);
impl AssetManagerRenderResource {
pub unsafe fn begin_extract(
&mut self,
asset_manager: &AssetManager,
) {
assert!(self.0.is_none());
self.0 = Some(Arc::new(force_to_static_lifetime(asset_manager)));
}
pub fn end_extract(&mut self) {
self.0
.take()
.to_owned()
.expect("Reference to AssetManager is still in use");
}
pub fn extract_ref(&self) -> AssetManagerExtractRef {
AssetManagerExtractRef(self.0.as_ref().unwrap().clone())
}
}
#[derive(Clone)]
pub struct AssetManagerExtractRef(Arc<&'static AssetManager>);
impl Deref for AssetManagerExtractRef {
type Target = AssetManager;
fn deref(&self) -> &Self::Target {
&*self.0
}
}