bones_asset/
network_handle.rs1use std::marker::PhantomData;
2
3use serde::{Deserialize, Serialize};
4
5use crate::prelude::*;
6
7#[derive(Serialize, Deserialize)]
9pub struct NetworkHandle<T> {
10 pub cid: Cid,
12 phantom: PhantomData<T>,
13}
14
15impl<T> NetworkHandle<T> {
16 pub fn from_cid(cid: Cid) -> Self {
18 Self {
19 cid,
20 phantom: PhantomData,
21 }
22 }
23
24 pub fn into_handle(&self, asset_server: &AssetServer) -> Handle<T> {
27 asset_server.try_get_handle_from_cid(&self.cid).unwrap_or_else(||
28 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)
29 )
30 }
31
32 pub fn into_untyped_handle(&self, asset_server: &AssetServer) -> UntypedHandle {
35 asset_server
36 .try_get_untyped_handle_from_cid(&self.cid)
37 .expect("Failed to lookup NetworkHandle content id in AssetServer. Is asset loaded? Invalid Cid?")
38 }
39}