Bevy Reflect
This crate enables you to dynamically interact with Rust types:
Derive the
Reflect
traitsInteract with fields using their names (for named structs) or indices (for tuple structs)
"Patch" your types with new values
Look up nested fields using "path strings"
Iterate over struct fields
Automatically serialize and deserialize via Serde (without explicit serde impls)
Trait "reflection"
Features
Derive the Reflect
traits
Interact with fields using their names
"Patch" your types with new values
Look up nested fields using "path strings"
Iterate over struct fields
Automatically serialize and deserialize via Serde (without explicit serde impls)
Trait "reflection"
Call a trait on a given &dyn Reflect
reference without knowing the underlying type!
Why make this?
The whole point of Rust is static safety! Why build something that makes it easy to throw it all away?
Some problems are inherently dynamic (scripting, some types of serialization / deserialization)
Sometimes the dynamic way is easier
Sometimes the dynamic way puts less burden on your users to derive a bunch of traits (this was a big motivator for the Bevy project)