pub struct Children { /* private fields */ }Expand description
Component containing a list of child entities.
This component stores references to all immediate children of an entity. The order of children is preserved and can be significant for rendering order or other order-dependent operations.
§Capacity and Performance
Internally uses a Vec<Entity>, so:
- Adding children is O(1) amortized
- Removing children is O(n) where n is the number of children
- Iteration is cache-friendly
For entities with many children, consider using with_capacity to
pre-allocate memory.
§Example
use goud_engine::ecs::Entity;
use goud_engine::ecs::components::Children;
let mut children = Children::new();
let child1 = Entity::new(1, 1);
let child2 = Entity::new(2, 1);
children.push(child1);
children.push(child2);
assert_eq!(children.len(), 2);
assert!(children.contains(child1));Implementations§
Source§impl Children
impl Children
Sourcepub fn with_capacity(capacity: usize) -> Children
pub fn with_capacity(capacity: usize) -> Children
Creates a Children component with pre-allocated capacity.
Use this when you know approximately how many children the entity will have.
Sourcepub fn from_slice(children: &[Entity]) -> Children
pub fn from_slice(children: &[Entity]) -> Children
Creates a Children component from a slice of entities.
Sourcepub fn remove_child(&mut self, child: Entity) -> bool
pub fn remove_child(&mut self, child: Entity) -> bool
Removes a child entity if it exists, preserving order.
Returns true if the child was found and removed, false otherwise.
This is O(n) as it must search for the child and shift elements.
Sourcepub fn swap_remove_child(&mut self, child: Entity) -> bool
pub fn swap_remove_child(&mut self, child: Entity) -> bool
Removes a child entity using swap-remove (faster but doesn’t preserve order).
Returns true if the child was found and removed, false otherwise.
O(n) for the search but O(1) for the actual removal.
Sourcepub fn get(&self, index: usize) -> Option<Entity>
pub fn get(&self, index: usize) -> Option<Entity>
Returns the child at the given index, if any.
Sourcepub fn index_of(&self, child: Entity) -> Option<usize>
pub fn index_of(&self, child: Entity) -> Option<usize>
Returns the index of a child entity, if it exists.
Returns Some(index) if found, None otherwise.
Sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only the children that satisfy the predicate.
§Example
use goud_engine::ecs::Entity;
use goud_engine::ecs::components::Children;
let mut children = Children::from_slice(&[
Entity::new(1, 1),
Entity::new(2, 1),
Entity::new(3, 1),
]);
// Keep only entities with even indices
children.retain(|e| e.index() % 2 == 0);
assert_eq!(children.len(), 1);
assert!(children.contains(Entity::new(2, 1)));Sourcepub fn sort_by_index(&mut self)
pub fn sort_by_index(&mut self)
Sorts children by their entity index for deterministic ordering.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Children
impl<'de> Deserialize<'de> for Children
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Children, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Children, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<'a> IntoIterator for &'a Children
impl<'a> IntoIterator for &'a Children
Source§impl IntoIterator for Children
impl IntoIterator for Children
Source§impl Serialize for Children
impl Serialize for Children
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Component for Children
impl Eq for Children
impl StructuralPartialEq for Children
Auto Trait Implementations§
impl Freeze for Children
impl RefUnwindSafe for Children
impl Send for Children
impl Sync for Children
impl Unpin for Children
impl UnsafeUnpin for Children
impl UnwindSafe for Children
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().