Skip to content

Commit

Permalink
Add a section mentioning GetPath in bevy_reflect
Browse files Browse the repository at this point in the history
The root doc for bevy_reflect doesn't mention `GetPath`. It's a fairly
useful featuree and I've seen people be surprised to learn it exists.
  • Loading branch information
nicopap committed Jun 19, 2023
1 parent 6b8db23 commit d08c5b1
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions crates/bevy_reflect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,31 @@
//!
//! All primitives and simple types implement `FromReflect` by relying on their [`Default`] implementation.
//!
//! # Path navigation
//!
//! The [`GetPath`] trait allows accessing arbitrary nested fields of a [`Reflect`] type.
//!
//! Using [`GetPath`], it is possible to use a path strings to access a specific field
//! of a reflected type.
//!
//! ```
//! # use bevy_reflect::{Reflect, GetPath};
//! #[derive(Reflect)]
//! struct MyStruct {
//! value: Vec<Option<u32>>
//! }
//!
//! let my_struct = MyStruct {
//! value: vec![None, None, Some(123)],
//! };
//! assert_eq!(
//! my_struct.path::<u32>(".value[2].0").unwrap(),
//! &123,
//! );
//! ```
//!
//! Check the [`GetPath`] documentation for more details.
//!
//! # Type Registration
//!
//! This crate also comes with a [`TypeRegistry`] that can be used to store and retrieve additional type metadata at runtime,
Expand Down

0 comments on commit d08c5b1

Please sign in to comment.