Skip to content

Commit

Permalink
Add as_slice to parent (#9871)
Browse files Browse the repository at this point in the history
# Objective
- Make it possible to write APIs that require a type or homogenous
storage for both `Children` & `Parent` that is agnostic to edge
direction.

## Solution
- Add a way to get the `Entity` from `Parent` as a slice.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Joseph <21144246+JoJoJet@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 22, 2023
1 parent 5c884c5 commit 0181d40
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions crates/bevy_hierarchy/src/components/parent.rs
Expand Up @@ -23,6 +23,16 @@ impl Parent {
pub fn get(&self) -> Entity {
self.0
}

/// Gets the parent [`Entity`] as a slice of length 1.
///
/// Useful for making APIs that require a type or homogenous storage
/// for both [`Children`] & [`Parent`] that is agnostic to edge direction.
///
/// [`Children`]: super::children::Children
pub fn as_slice(&self) -> &[Entity] {
std::slice::from_ref(&self.0)
}
}

// TODO: We need to impl either FromWorld or Default so Parent can be registered as Reflect.
Expand Down

0 comments on commit 0181d40

Please sign in to comment.