use std::marker::PhantomData;
use serde::{Deserialize, Serialize};
use crate::prelude::*;
#[derive(Serialize, Deserialize)]
pub struct NetworkHandle<T> {
pub cid: Cid,
phantom: PhantomData<T>,
}
impl<T> NetworkHandle<T> {
pub fn from_cid(cid: Cid) -> Self {
Self {
cid,
phantom: PhantomData,
}
}
pub fn into_handle(&self, asset_server: &AssetServer) -> Handle<T> {
asset_server.try_get_handle_from_cid(&self.cid).unwrap_or_else(||
panic!("Failed to lookup NetworkHandle content id: {} in AssetServer. Asset may not be loaded, or this client does not have exact copy of remote", &self.cid)
)
}
pub fn into_untyped_handle(&self, asset_server: &AssetServer) -> UntypedHandle {
asset_server
.try_get_untyped_handle_from_cid(&self.cid)
.expect("Failed to lookup NetworkHandle content id in AssetServer. Is asset loaded? Invalid Cid?")
}
}