I am trying to write a ray tracer in Rust, and my code lives here:
However, I have hit a roadblock on how to properly do dynamic dispatch and polymorphism.
camera/mod.rs, I have the base
Trait that has two functions,
generate_camera_ray(), and a
struct PinholeCamera that implements them. In
src/lib.rs, I parse the scene file and look for the camera type, and I need to call the corresponding
Camera. I did look up the trait objects section of the book, however, I cannot get my code to compile. That brings me to have several questions:
Is this the proper way to do dynamic dispatch? Most likely no, but a hint in the right direction would be highly appreciated.
src/lib.rs, I have a
matchblock that I use to construct the
cameraobject, before storing it in
SceneConfig. Is variable shadowing the idiomatic way to do this? (Since the camera object will not be living outside the match block…)
Any help would be appreciated!