Sketched out program manager API

This commit is contained in:
Mikayla Maki 2022-09-01 20:07:30 -07:00
parent 4779eebdce
commit 7730039e31
2 changed files with 76 additions and 1 deletions

View file

@ -5083,6 +5083,7 @@ impl Drop for AnyModelHandle {
}
}
#[derive(Hash, PartialEq, Eq, Debug)]
pub struct AnyWeakModelHandle {
model_id: usize,
model_type: TypeId,
@ -5092,6 +5093,26 @@ impl AnyWeakModelHandle {
pub fn upgrade(&self, cx: &impl UpgradeModelHandle) -> Option<AnyModelHandle> {
cx.upgrade_any_model_handle(self)
}
pub fn model_type(&self) -> TypeId {
self.model_type
}
fn is<T: 'static>(&self) -> bool {
TypeId::of::<T>() == self.model_type
}
pub fn downcast<T: Entity>(&self) -> Option<WeakModelHandle<T>> {
if self.is::<T>() {
let result = Some(WeakModelHandle {
model_id: self.model_id,
model_type: PhantomData,
});
result
} else {
None
}
}
}
impl<T: Entity> From<WeakModelHandle<T>> for AnyWeakModelHandle {