How to allow mutable methods to be used, but not let the entire struct be replaced.

45 points rhedgeco

I am working on a rendering engine, and I have run into a bit of a strange problem with wgpu and winit. I have created a struct that manages all the window, hardware, and surface.

I want the winit window able to be changed however one may deem fit. that may be changing the title, resizablity, etc. So I have a method that provides mutable access to the window that the struct is managing. However, this is a problem because now that window can just be replaced entirely with a new window. This is an issue because now the surface that the renderer is using is not guaranteed to be valid anymore since it is directly linked to a window that could be replaced.

How do I go about allowing the window to be modified, without breaking the contract that I am trying to keep with the rendering surface? Any help would be appreciated. Thanks.

Edit: turns out all the methods on the winit window don't require mutability, and thus resolves the issues I have. However I am still curious about how I would solve this if it were a problem.