This is kind of a Rust question in general. I want to allow the data which is drawn on the canvas to change and update in response to user input. The canvas::Program::draw
trait method does not accept data outside of &self
and &mut State
, so I need a way to store the data in self
or state
while still being able to modify it freely. I’m encapsulating the canvas into another struct that could be used as a widget so I can customize some behavior and add some niceties. Because of that, ideally I would not like the user of this struct to need to modify a public member to store new data / modify the already stored data. I would like for them to be able to call some function which adds new data. I can do that easily if I make the struct hold a Vec for the data, and then the function just pushes onto that. But this requires (?) copying the data passed to the function into the Vec, and there could potentially be a lot of data. Is there a design pattern or something that Rustaceans lean on to accomplish something like this?