New to Rust - having fun - and looking for some advise.
I'm implementing a 3d graphics system. The "scene" is a list of various kinds of objects (eg, Sphere, Box, Camera, Light). Then there are several modules for different sub-systems (viewing, rendering, simulation, etc). Each of these sub-systems define a trait which defined the API objects need to implement to participate in that module. For instance, the viewing sub-system defines "Viewable" which has a "draw()" function. The rendering system defined "Renderable" which has a "bounds()" function.
Ok, so each of those system have a list of objects which are registered with that system, like:
objects : Vec<Box<dyn Renderable>>
So, now I want a list of all these objects no matter which sub-system traits they implement. Something like "Sphere" will implement all of them. "Camera" will only implement some of them. And then from this list I will want to be able to introspect "which objects in this list implement the X trait"? Pseudo code for rendering might be:
r is a renderer
for each object in scene.objects {
if object implement the trait "Renderable" {
r.add(object); // ?? r.add(object as Renderable)??
}
}
Questions
1: Am I thinking about this in a Rust-like way?
2: Can anyone suggest how to implement this?