Skip to content

What are the reflect attribute parameters? #2503

Answered by cart
Alainx277 asked this question in Q&A
Discussion options

You must be logged in to vote

These are for "trait reflection". It is a way to connect trait methods to the reflection system. Without knowing the underlying type of a Reflect reference, you can call any registered trait method. Here is an example that explains this in a bit more detail.

Due to the nature of the implementation, you generally can't do this for arbitrary traits. It must be explicitly supported by each trait. You can do this using the reflect_trait proc_macro, or by implementing it manually. The reflect crate provides built in support for common traits, such as Serialize, Deserialize, PartialEq, and Hash. These "built in" traits can be accessed directly on the Reflect type:

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by cart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants