Skip to content

Commit befb8d9

Browse files
committed
Add a section mentioning GetPath in bevy_reflect
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.
1 parent 105463f commit befb8d9

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

crates/bevy_reflect/src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,31 @@
224224
//!
225225
//! All primitives and simple types implement `FromReflect` by relying on their [`Default`] implementation.
226226
//!
227+
//! # Path navigation
228+
//!
229+
//! The [`GetPath`] trait allows accessing arbitrary nested fields of a [`Reflect`] type.
230+
//!
231+
//! Using [`GetPath`], it is possible to use a path strings to access a specific field
232+
//! of a reflected type.
233+
//!
234+
//! ```
235+
//! # use bevy_reflect::{Reflect, GetPath};
236+
//! #[derive(Reflect)]
237+
//! struct MyStruct {
238+
//! value: Vec<Option<u32>>
239+
//! }
240+
//!
241+
//! let my_struct = MyStruct {
242+
//! value: vec![None, None, Some(123)],
243+
//! };
244+
//! assert_eq!(
245+
//! my_struct.path::<u32>(".value[2].0").unwrap(),
246+
//! &123,
247+
//! );
248+
//! ```
249+
//!
250+
//! Check the [`GetPath`] documentation for more details.
251+
//!
227252
//! # Type Registration
228253
//!
229254
//! This crate also comes with a [`TypeRegistry`] that can be used to store and retrieve additional type metadata at runtime,

0 commit comments

Comments
 (0)