use std::fmt;
use super::*;
pub use lifespan::*;
pub use offspring::*;
pub use state::*;
pub mod lifespan;
pub mod offspring;
pub mod state;
pub type Id = usize;
pub trait Entity<'e> {
type Kind;
type Context;
fn id(&self) -> Id;
fn kind(&self) -> Self::Kind;
fn location(&self) -> Option<Location> {
None
}
fn scope(&self) -> Option<Scope> {
None
}
fn lifespan(&self) -> Option<Lifespan> {
None
}
fn lifespan_mut(&mut self) -> Option<&mut Lifespan> {
None
}
fn state(&self) -> Option<&dyn State> {
None
}
fn state_mut(&mut self) -> Option<&mut dyn State> {
None
}
fn observe(
&mut self,
_: Option<Neighborhood<'_, 'e, Self::Kind, Self::Context>>,
) -> Result<(), Error> {
Ok(())
}
fn react(
&mut self,
_: Option<Neighborhood<'_, 'e, Self::Kind, Self::Context>>,
) -> Result<(), Error> {
Ok(())
}
fn offspring(
&mut self,
) -> Option<Offspring<'e, Self::Kind, Self::Context>> {
None
}
fn draw(&self, _: &mut Self::Context, _: Transform) -> Result<(), Error> {
Ok(())
}
}
#[cfg(not(feature = "parallel"))]
pub type EntityTrait<'e, K, C> = dyn Entity<'e, Kind = K, Context = C> + 'e;
#[cfg(feature = "parallel")]
pub type EntityTrait<'e, K, C> =
dyn Entity<'e, Kind = K, Context = C> + 'e + Send + Sync;
impl<'e, K: fmt::Debug, C> fmt::Debug for EntityTrait<'e, K, C> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Entity")
.field("id", &self.id())
.field("kind", &self.kind())
.finish()
}
}