My struct contains a few “graphical” items, that need to be laid out on a page. I want to make sure that each call to layout and item is called with an instance of the same kind of page, otherwise their final co-ordinates will be jumbled.
Now that I think about it, I might be able to just make the Layout struct have a reference to a page. I had been avoiding that because of lifetime issues, since I could not mutate the page as long as any layouts existed if the layouts had a reference to the page, but maybe I can use a second type (e.g. FinalisedLayout) that doesn’t hold a reference to work around that.
edited to add:
My flow currently is something like this:
let mut p = Page::new();
let mut front = Layout::new();
front.add(x, y, z);
let mut back = Layout::new();
let mut r = Renderer::new(&mut p);
The problem I ran into was that
back are needed after the call to
Renderer::new(...), which needs a
&mut Page, so I was avoiding having Layout keep a reference to Page.