|
|
@ -32,13 +32,52 @@ impl Archetype { |
|
|
|
pub fn has(&self, component: impl Into<Component>) -> bool { |
|
|
|
pub fn has(&self, component: impl Into<Component>) -> bool { |
|
|
|
self.components.binary_search(&component.into()).is_ok() |
|
|
|
self.components.binary_search(&component.into()).is_ok() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn add(&mut self, component: impl Into<Component>) { |
|
|
|
|
|
|
|
let component = component.into(); |
|
|
|
|
|
|
|
if let Err(index) = self.components.binary_search(&component) { |
|
|
|
|
|
|
|
self.components.insert(index, component) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn remove(&mut self, component: impl Into<Component>) { |
|
|
|
|
|
|
|
let component = component.into(); |
|
|
|
|
|
|
|
if let Ok(index) = self.components.binary_search(&component) { |
|
|
|
|
|
|
|
self.components.remove(index); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[inline] |
|
|
|
|
|
|
|
#[must_use] |
|
|
|
|
|
|
|
pub fn with(mut self, component: impl Into<Component>) -> Self { |
|
|
|
|
|
|
|
self.add(component); |
|
|
|
|
|
|
|
self |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[inline] |
|
|
|
|
|
|
|
#[must_use] |
|
|
|
|
|
|
|
pub fn without(mut self, component: impl Into<Component>) -> Self { |
|
|
|
|
|
|
|
self.remove(component); |
|
|
|
|
|
|
|
self |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<T> FromIterator<T> for Archetype |
|
|
|
impl<T> FromIterator<T> for Archetype |
|
|
|
where |
|
|
|
where |
|
|
|
T: Into<Component>, |
|
|
|
T: Into<Component>, |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
#[inline] |
|
|
|
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self { |
|
|
|
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self { |
|
|
|
Self::new(iter) |
|
|
|
Self::new(iter) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl IntoIterator for Archetype { |
|
|
|
|
|
|
|
type Item = Component; |
|
|
|
|
|
|
|
type IntoIter = std::vec::IntoIter<Self::Item>; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[inline] |
|
|
|
|
|
|
|
fn into_iter(self) -> Self::IntoIter { |
|
|
|
|
|
|
|
self.components.into_iter() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|