bevy/crates
Gino Valente 8cd59b6a03 bevy_reflect: Pre-parsed paths (#7321)
# Objective

> ℹ️ **This is an adoption of #4081 by @james7132**

Fixes #4080.

Provide a way to pre-parse reflection paths so as to avoid having to parse at each call to `GetPath::path` (or similar method).

## Solution

Adds the `ParsedPath` struct (named `FieldPath` in the original PR) that parses and caches the sequence of accesses to a reflected element. This is functionally similar to the `GetPath` trait, but removes the need to parse an unchanged path more than once.

### Additional Changes

Included in this PR from the original is cleaner code as well as the introduction of a new pathing operation: field access by index. This allows struct and struct variant fields to be accessed in a more performant (albeit more fragile) way if needed. This operation is faster due to not having to perform string matching. As an example, if we wanted the third field on a struct, we'd write `#2`—where `#` denotes indexed access and `2` denotes the desired field index.

This PR also contains improved documentation for `GetPath` and friends, including renaming some of the methods to be more clear to the end-user with a reduced risk of getting them mixed up.

### Future Work

There are a few things that could be done as a separate PR (order doesn't matter— they could be followup PRs or done in parallel). These are:

- [x] ~~Add support for `Tuple`. Currently, we hint that they work but they do not.~~ See #7324
- [ ] Cleanup `ReflectPathError`. I think it would be nicer to give `ReflectPathError` two variants: `ReflectPathError::ParseError` and `ReflectPathError::AccessError`, with all current variants placed within one of those two. It's not obvious when one might expect to receive one type of error over the other, so we can help by explicitly categorizing them.

---

## Changelog

- Cleaned up `GetPath` logic
- Added `ParsedPath` for cached reflection paths
- Added new reflection path syntax: struct field access by index (example syntax: `foo#1`)
- Renamed methods on `GetPath`:
  - `path` -> `reflect_path`
  - `path_mut` -> `reflect_path_mut`
  - `get_path` -> `path`
  - `get_path_mut` -> `path_mut`

## Migration Guide

`GetPath` methods have been renamed according to the following:
- `path` -> `reflect_path`
- `path_mut` -> `reflect_path_mut`
- `get_path` -> `path`
- `get_path_mut` -> `path_mut`


Co-authored-by: Gino Valente <gino.valente.code@gmail.com>
2023-01-22 23:35:33 +00:00
..
bevy_animation Basic adaptive batching for parallel query iteration (#4777) 2023-01-20 08:47:20 +00:00
bevy_app Pipelined Rendering (#6503) 2023-01-19 23:45:46 +00:00
bevy_asset fix load_internal_binary_asset with debug_asset_server (#7246) 2023-01-18 02:07:26 +00:00
bevy_audio AudioOutput is actually a normal resource now, not a non-send resource (#7262) 2023-01-18 17:20:26 +00:00
bevy_core Break CorePlugin into TaskPoolPlugin, TypeRegistrationPlugin, FrameCountPlugin. (#7083) 2023-01-05 11:42:35 +00:00
bevy_core_pipeline Support recording multiple CommandBuffers in RenderContext (#7248) 2023-01-22 00:21:55 +00:00
bevy_derive Fix ndk-macro link (#7027) 2022-12-25 05:06:03 +00:00
bevy_diagnostic Fix dynamic linking (on linux) (#7333) 2023-01-22 20:41:28 +00:00
bevy_dylib Release 0.9.0 (#6568) 2022-11-12 20:01:29 +00:00
bevy_dynamic_plugin Adapt path type of dynamically_load_plugin (#6734) 2022-12-05 23:39:43 +00:00
bevy_ecs Added resource_id and changed init_resource and init_non_send_resource to return ComponentId (#7284) 2023-01-20 19:08:04 +00:00
bevy_ecs_compile_fail_tests Fix clippy lints and failed test with Rust 1.66 (#6945) 2022-12-15 18:05:15 +00:00
bevy_encase_derive add helper for macro to get either bevy::x or bevy_x depending on how it was imported (#7164) 2023-01-11 21:12:02 +00:00
bevy_gilrs Gamepad events refactor (#6965) 2023-01-09 19:24:52 +00:00
bevy_gltf enum Visibility component (#6320) 2022-12-25 00:39:29 +00:00
bevy_hierarchy Add ReplaceChildren and ClearChildren EntityCommands (#6035) 2023-01-16 21:24:15 +00:00
bevy_input Fix incorrect behavior of just_pressed and just_released in Input<GamepadButton> (#7238) 2023-01-16 21:09:24 +00:00
bevy_internal Fix dynamic linking (on linux) (#7333) 2023-01-22 20:41:28 +00:00
bevy_log Fix suppression of all console logs when trace_tracy is enabled (#6955) 2022-12-20 23:45:43 +00:00
bevy_macro_utils Use toml_edit instead of toml (#7327) 2023-01-22 19:41:48 +00:00
bevy_math Improve code/comments for Ray::intersect_plane and its tests (#6823) 2022-12-05 22:49:06 +00:00
bevy_mikktspace Release 0.9.0 (#6568) 2022-11-12 20:01:29 +00:00
bevy_pbr Standard Material Blend Modes (#6644) 2023-01-21 21:46:53 +00:00
bevy_ptr Improve safety for CommandQueue internals (#7039) 2023-01-19 03:04:39 +00:00
bevy_reflect bevy_reflect: Pre-parsed paths (#7321) 2023-01-22 23:35:33 +00:00
bevy_reflect_compile_fail_tests bevy_reflect: Add compile fail tests for bevy_reflect (#7041) 2023-01-02 21:07:33 +00:00
bevy_render Support recording multiple CommandBuffers in RenderContext (#7248) 2023-01-22 00:21:55 +00:00
bevy_scene Fix beta clippy lints (#7154) 2023-01-11 09:51:22 +00:00
bevy_sprite Changed Msaa to Enum (#7292) 2023-01-20 14:25:21 +00:00
bevy_tasks Pipelined Rendering (#6503) 2023-01-19 23:45:46 +00:00
bevy_text Allow users of Text/TextBundle to choose from glyph_brush_layout's BuiltInLineBreaker options. (#7283) 2023-01-21 00:17:11 +00:00
bevy_time Add bevy_ecs::schedule_v3 module (#6587) 2023-01-17 01:39:17 +00:00
bevy_transform Basic adaptive batching for parallel query iteration (#4777) 2023-01-20 08:47:20 +00:00
bevy_ui Optimize color computation in prepare_uinodes (#7311) 2023-01-22 06:51:31 +00:00
bevy_utils Add bevy_ecs::schedule_v3 module (#6587) 2023-01-17 01:39:17 +00:00
bevy_window Allow not preventing default event behaviors on wasm (#7304) 2023-01-22 23:35:32 +00:00
bevy_winit Allow not preventing default event behaviors on wasm (#7304) 2023-01-22 23:35:32 +00:00