bevy/crates/bevy_scene/src
Carter Anderson b73811d40e
Remove ChildOf::get and Deref impl (#18080)
# Objective

There are currently three ways to access the parent stored on a ChildOf
relationship:

1. `child_of.parent` (field accessor)
2. `child_of.get()` (get function)
3. `**child_of` (Deref impl)

I will assert that we should only have one (the field accessor), and
that the existence of the other implementations causes confusion and
legibility issues. The deref approach is heinous, and `child_of.get()`
is significantly less clear than `child_of.parent`.

## Solution

Remove `impl Deref for ChildOf` and `ChildOf::get`.

The one "downside" I'm seeing is that:

```rust
entity.get::<ChildOf>().map(ChildOf::get)
```
Becomes this:

```rust
entity.get::<ChildOf>().map(|c| c.parent)
```

I strongly believe that this is worth the increased clarity and
consistency. I'm also not really a huge fan of the "pass function
pointer to map" syntax. I think most people don't think this way about
maps. They think in terms of a function that takes the item in the
Option and returns the result of some action on it.

## Migration Guide

```rust
// Before
**child_of
// After
child_of.parent

// Before
child_of.get()
// After
child_of.parent

// Before
entity.get::<ChildOf>().map(ChildOf::get)
// After
entity.get::<ChildOf>().map(|c| c.parent)
```
2025-02-27 23:11:03 +00:00
..
components.rs Add missing #[reflect(Component, Default)] to SceneRoot and DynamicSceneRoot. (#16816) 2024-12-15 19:18:22 +00:00
dynamic_scene_builder.rs Allow users to register their own disabling components / default query filters (#17768) 2025-02-11 18:25:32 +00:00
dynamic_scene.rs Remove ChildOf::get and Deref impl (#18080) 2025-02-27 23:11:03 +00:00
lib.rs Only despawn scene entities still in the hierarchy (#17938) 2025-02-22 01:53:08 +00:00
scene_filter.rs Move hashbrown and foldhash out of bevy_utils (#17460) 2025-01-23 16:46:08 +00:00
scene_loader.rs Deny derive_more error feature and replace it with thiserror (#16684) 2024-12-06 17:03:55 +00:00
scene_spawner.rs Only despawn scene entities still in the hierarchy (#17938) 2025-02-22 01:53:08 +00:00
scene.rs Improved Entity Mapping and Cloning (#17687) 2025-02-06 22:13:41 +00:00
serde.rs Improved Entity Mapping and Cloning (#17687) 2025-02-06 22:13:41 +00:00