terrified to start testing
This commit is contained in:
@@ -1,33 +1,31 @@
|
||||
use std::any::Any;
|
||||
use std::fmt::Debug;
|
||||
use std::sync::Arc;
|
||||
use std::rc::Rc;
|
||||
|
||||
use orchid_base::{BoxedIter, box_empty, box_once};
|
||||
use ordered_float::NotNan;
|
||||
|
||||
use crate::api;
|
||||
use crate::other_system::{DynSystemHandle, SystemHandle};
|
||||
use crate::system::{DynSystem, System, SystemCard};
|
||||
use crate::{DynSystem, DynSystemHandle, System, SystemCard, SystemHandle, api};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Cted<Ctor: SystemCtor + ?Sized> {
|
||||
pub deps: <Ctor::Deps as DepDef>::Sat,
|
||||
pub inst: Arc<Ctor::Instance>,
|
||||
pub inst: Rc<Ctor::Instance>,
|
||||
}
|
||||
impl<C: SystemCtor + ?Sized> Clone for Cted<C> {
|
||||
fn clone(&self) -> Self { Self { deps: self.deps.clone(), inst: self.inst.clone() } }
|
||||
}
|
||||
pub trait DynCted: Debug + 'static {
|
||||
fn as_any(&self) -> &dyn Any;
|
||||
fn as_any(self: Rc<Self>) -> Rc<dyn Any>;
|
||||
fn deps<'a>(&'a self) -> BoxedIter<'a, &'a (dyn DynSystemHandle + 'a)>;
|
||||
fn inst(&self) -> Arc<dyn DynSystem>;
|
||||
fn inst(&self) -> Rc<dyn DynSystem>;
|
||||
}
|
||||
impl<C: SystemCtor + ?Sized> DynCted for Cted<C> {
|
||||
fn as_any(&self) -> &dyn Any { self }
|
||||
fn as_any(self: Rc<Self>) -> Rc<dyn Any> { self }
|
||||
fn deps<'a>(&'a self) -> BoxedIter<'a, &'a (dyn DynSystemHandle + 'a)> { self.deps.iter() }
|
||||
fn inst(&self) -> Arc<dyn DynSystem> { self.inst.clone() }
|
||||
fn inst(&self) -> Rc<dyn DynSystem> { self.inst.clone() }
|
||||
}
|
||||
pub type CtedObj = Arc<dyn DynCted>;
|
||||
pub type CtedObj = Rc<dyn DynCted>;
|
||||
|
||||
pub trait DepSat: Debug + Clone + 'static {
|
||||
fn iter<'a>(&'a self) -> BoxedIter<'a, &'a (dyn DynSystemHandle + 'a)>;
|
||||
@@ -61,7 +59,8 @@ impl DepDef for () {
|
||||
|
||||
pub trait SystemCtor: Debug + 'static {
|
||||
type Deps: DepDef;
|
||||
type Instance: System;
|
||||
type Instance: System<Ctor = Self>;
|
||||
type Card: SystemCard<Ctor = Self>;
|
||||
const NAME: &'static str;
|
||||
const VERSION: f64;
|
||||
/// Create a system instance.
|
||||
@@ -85,8 +84,8 @@ impl<T: SystemCtor> DynSystemCtor for T {
|
||||
fn new_system(&self, api::NewSystem { system: _, id: _, depends }: &api::NewSystem) -> CtedObj {
|
||||
let mut ids = depends.iter().copied();
|
||||
let deps = T::Deps::create(&mut || ids.next().unwrap());
|
||||
let inst = Arc::new(self.inst(deps.clone()));
|
||||
Arc::new(Cted::<T> { deps, inst })
|
||||
let inst = Rc::new(self.inst(deps.clone()));
|
||||
Rc::new(Cted::<T> { deps, inst })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user