use std::fmt::{Debug, Display, Formatter};
use std::hash::{Hash, Hasher};
use crate::component::pool::ComponentPool;
use crate::object::ObjectRef;
pub trait Component: Sized
{
type Pool: ComponentPool<Self>;
}
pub struct ComponentRef<T: Component>
{
pub index: usize,
useless: std::marker::PhantomData<T>
}
impl<T: Component> Copy for ComponentRef<T> {}
impl<T: Component> Clone for ComponentRef<T>
{
fn clone(&self) -> Self
{
Self {
index: self.index,
useless: self.useless
}
}
}
impl<T: Component> PartialEq for ComponentRef<T>
{
fn eq(&self, other: &Self) -> bool
{
self.index == other.index
}
}
impl<T: Component> Eq for ComponentRef<T> { }
impl<T: Component> Hash for ComponentRef<T>
{
fn hash<H: Hasher>(&self, state: &mut H)
{
self.index.hash(state)
}
}
impl<T: Component> Debug for ComponentRef<T>
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result
{
<usize as Debug>::fmt(&self.index, f)
}
}
impl<T: Component> Display for ComponentRef<T>
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result
{
<usize as Display>::fmt(&self.index, f)
}
}
impl<T: Component> ComponentRef<T>
{
pub fn new(index: usize) -> Self
{
Self {
index,
useless: Default::default()
}
}
}
pub trait Clear
{
fn clear(&mut self, entity: ObjectRef);
}
pub type Pool<T> = <T as Component>::Pool;