@buherator check out Box::new(T).
If you want mutation etc you may want to also check out RefCell and mayb3 even UnsafeCell!
[If I'm reading your PG example correctly]
@buherator I’m not really sure what you mean by incapsulate the initialisation. Maybe showing the code you are getting an error from would help.
@buherator@infosec.place Can you be more specific about what you want to do?
@buherator@infosec.place Yeah, you'll need some indirection here. You can't move session while it is borrowed. Alternatively, you can keep the widgets in the session (e.g., in a vec or smth) and only offer (mutably) borrowed access to the widgets by an ID or something. It just depends on what's appropriate for your use case; presumably, widgets should always be deinitialized when the session is, so the session should "own" the widgets.
@buherator@infosec.place Then it's time for an Rc<RefCell<Session>> instead of a lifetime (or Arc<RwLock<...>> if asynchronous). Just be careful to avoid cycles. :)
@buherator@infosec.place For deinit_all you definitely need some wrapper object keeping track of the widgets, but that should be compatible here. If the session can die independently, use Weak instead of Rc/Arc.
@buherator@infosec.place Yeah, Rust will really force you to be careful here. In other languages, you might initialize the widget with a pointer, but then if you move the value, the pointer is invalid. Similarly with concurrent access to the session object. You're prohibited from constructions which are potentially faulty.
@buherator Self referential structs, in most of the codebases I work in on would be considered a bit of an anti pattern -- for UI, a lot of the ... 'opinions' of Rust become 'tricky'.
Keep at it :)
@buherator Iced, and egui are probably the two gotos for all my projects (unless you need 3d in which case I'd go with Bevy or Godot).
The web ppl like Dioxus, but I dunno anything about electron or the web.