-
|
Please bear with me, I'm new to Rust and Bevy. I want to print information about an entity without specifying the format at length every time. Hence, I'm looking to implement fmt::Display. As my first attempt, I've written the implementation for the struct-deriving-from-Bundle that I used to create the entity (and its peers) - and have additionally written the implementation for the enum type of one of its contained fields - but I realize now that this is probably not what I am after - by the time I want to print the information, I am interacting not with a bundle (IIUC) but rather a permutation of a Query generic subtype - say, Query<Entity, &MyComponent1, &MyComponent2>. Is the straightforward answer to instead (or additionally) implement fmt::Display for a corresponding QueryData? (The immediate challenge I'm envisioning with said approach is: how do I deal with cases where I want to query different subsets of the entity's components, without having to re-implement fmt::Display for each combination?) Maybe there is a different approach - perhaps involving the Entity type or some kind of cast - of which I'm unaware? Code for flavor/visual, for those interested (the most relevant portion is at the bottom - additional lines included for context in case desired): |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
It seems to me like maybe I should stick to implementing Display on individual components that need them, and if I want to avoid repetition when printing information, pass components into a utility function - perhaps with some parameters optional - and write to e.g. stdout from there. |
Beta Was this translation helpful? Give feedback.
It seems to me like maybe I should stick to implementing Display on individual components that need them, and if I want to avoid repetition when printing information, pass components into a utility function - perhaps with some parameters optional - and write to e.g. stdout from there.