pub trait HierarchyQueryExt<'w, 's, D: QueryData, F: QueryFilter> {
// Required methods
fn parent(&'w self, entity: Entity) -> Option<Entity>
where D::ReadOnly: WorldQuery<Item<'w> = &'w Parent>;
fn children(&'w self, entity: Entity) -> &'w [Entity]
where D::ReadOnly: WorldQuery<Item<'w> = &'w Children>;
fn root_ancestor(&'w self, entity: Entity) -> Entity
where D::ReadOnly: WorldQuery<Item<'w> = &'w Parent>;
fn iter_leaves(
&'w self,
entity: Entity,
) -> impl Iterator<Item = Entity> + 'w
where D::ReadOnly: WorldQuery<Item<'w> = &'w Children>;
fn iter_siblings(&'w self, entity: Entity) -> impl Iterator<Item = Entity>
where D::ReadOnly: WorldQuery<Item<'w> = (Option<&'w Parent>, Option<&'w Children>)>;
fn iter_descendants(
&'w self,
entity: Entity,
) -> DescendantIter<'w, 's, D, F> ⓘ
where D::ReadOnly: WorldQuery<Item<'w> = &'w Children>;
fn iter_descendants_depth_first(
&'w self,
entity: Entity,
) -> DescendantDepthFirstIter<'w, 's, D, F> ⓘ
where D::ReadOnly: WorldQuery<Item<'w> = &'w Children>;
fn iter_ancestors(&'w self, entity: Entity) -> AncestorIter<'w, 's, D, F> ⓘ
where D::ReadOnly: WorldQuery<Item<'w> = &'w Parent>;
}
Expand description
An extension trait for Query
that adds hierarchy related methods.
Required Methods§
Sourcefn parent(&'w self, entity: Entity) -> Option<Entity>
fn parent(&'w self, entity: Entity) -> Option<Entity>
Returns the parent Entity
of the given entity
, if any.
Sourcefn children(&'w self, entity: Entity) -> &'w [Entity]
fn children(&'w self, entity: Entity) -> &'w [Entity]
Returns a slice over the Children
of the given entity
.
This may be empty if the entity
has no children.
Sourcefn root_ancestor(&'w self, entity: Entity) -> Entity
fn root_ancestor(&'w self, entity: Entity) -> Entity
Returns the topmost ancestor of the given entity
.
This may be the entity itself if it has no parent.
Sourcefn iter_leaves(&'w self, entity: Entity) -> impl Iterator<Item = Entity> + 'w
fn iter_leaves(&'w self, entity: Entity) -> impl Iterator<Item = Entity> + 'w
Returns an Iterator
of Entity
s over the leaves of the hierarchy that are underneath this entity
.
Only entities which have no children are considered leaves. This will not include the entity itself, and will not include any entities which are not descendants of the entity, even if they are leaves in the same hierarchical tree.
Traverses the hierarchy depth-first.
Sourcefn iter_siblings(&'w self, entity: Entity) -> impl Iterator<Item = Entity>
fn iter_siblings(&'w self, entity: Entity) -> impl Iterator<Item = Entity>
Sourcefn iter_descendants(&'w self, entity: Entity) -> DescendantIter<'w, 's, D, F> ⓘ
fn iter_descendants(&'w self, entity: Entity) -> DescendantIter<'w, 's, D, F> ⓘ
Returns an Iterator
of Entity
s over all of entity
s descendants.
Can only be called on a Query
of Children
(i.e. Query<&Children>
).
Traverses the hierarchy breadth-first and does not include the entity itself.
§Examples
fn system(entity: Single<Entity, With<Marker>>, children_query: Query<&Children>) {
for descendant in children_query.iter_descendants(*entity) {
// Do something!
}
}
Sourcefn iter_descendants_depth_first(
&'w self,
entity: Entity,
) -> DescendantDepthFirstIter<'w, 's, D, F> ⓘ
fn iter_descendants_depth_first( &'w self, entity: Entity, ) -> DescendantDepthFirstIter<'w, 's, D, F> ⓘ
Returns an Iterator
of Entity
s over all of entity
s descendants.
Can only be called on a Query
of Children
(i.e. Query<&Children>
).
This is a depth-first alternative to HierarchyQueryExt::iter_descendants
.
Sourcefn iter_ancestors(&'w self, entity: Entity) -> AncestorIter<'w, 's, D, F> ⓘ
fn iter_ancestors(&'w self, entity: Entity) -> AncestorIter<'w, 's, D, F> ⓘ
Returns an Iterator
of Entity
s over all of entity
s ancestors.
Does not include the entity itself.
Can only be called on a Query
of Parent
(i.e. Query<&Parent>
).
§Examples
fn system(entity: Single<Entity, With<Marker>>, parent_query: Query<&Parent>) {
for ancestor in parent_query.iter_ancestors(*entity) {
// Do something!
}
}
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.