Hi!
I'm trying to write an application that manipulates visual objects such as circle, rectangle, etc.
Naturally, I've written traits such as the one below to group functionalities and implemented them across multiple shapes
pub trait SetPosition{
fn move_by(&mut self, x:f32, y:f32); //shift object's position
fn move_to(&mut self, x:f32, y:f32); // move to a specific point
}
I'm now exploring the use of arena allocator (e.g. generational-arena) to contain all object data and use only index to operate on the object data (due to reference cycles, etc.)
The problem I have is with implementing these traits for the index type I get from arena allocation. I would like to stay as close to my original trait definition as possible, but now I have to pass around the arena for every method:
let mut c = circle();
let mut arena = Arena::new();
let mut c_idx = arena.add(c); // Add object and return it's index
c.move_by(1,1); // This is previous method
c_idx.move_by(&mut arena, 1, 1) // Now arena must also be passed as an input
Also, this change requires that I define a new trait for every existing trait due to the change in each function signature. I find this cumbersome and hard to maintain.
Is there a more ergonomic design pattern which I could use?
Thank you!