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>
This commit is contained in:
iiYese 2023-09-22 07:27:58 +01:00 committed by GitHub
parent 5c884c5a15
commit 0181d40d83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.