use legion::prelude::{Resources, Runnable, Schedulable, World}; use std::borrow::Cow; pub enum System { Schedulable(Box), ThreadLocal(Box), ThreadLocalFn((&'static str, Box)), } impl System { pub fn name(&self) -> Cow<'static, str> { match *self { System::Schedulable(ref schedulable) => schedulable.name().name(), System::ThreadLocal(ref runnable) => runnable.name().name(), System::ThreadLocalFn((ref name, ref _thread_local_fn)) => Cow::Borrowed(name), } } } impl From> for System { fn from(system: Box) -> Self { System::Schedulable(system) } } impl From> for System { fn from(system: Box) -> Self { System::ThreadLocal(system) } } impl From for System where T: FnMut(&mut World, &mut Resources) + 'static, { fn from(system: T) -> Self { System::ThreadLocalFn((std::any::type_name::(), Box::new(system))) } }