Skip to content

Commit 0181d40

Browse files
iiYesealice-i-cecilejoseph-gio
authored
Add as_slice to parent (#9871)
# 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>
1 parent 5c884c5 commit 0181d40

File tree

1 file changed

+10
-0
lines changed
  • crates/bevy_hierarchy/src/components

1 file changed

+10
-0
lines changed

crates/bevy_hierarchy/src/components/parent.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ impl Parent {
2323
pub fn get(&self) -> Entity {
2424
self.0
2525
}
26+
27+
/// Gets the parent [`Entity`] as a slice of length 1.
28+
///
29+
/// Useful for making APIs that require a type or homogenous storage
30+
/// for both [`Children`] & [`Parent`] that is agnostic to edge direction.
31+
///
32+
/// [`Children`]: super::children::Children
33+
pub fn as_slice(&self) -> &[Entity] {
34+
std::slice::from_ref(&self.0)
35+
}
2636
}
2737

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

0 commit comments

Comments
 (0)