I'm trying to assign a child struct, but after the parent was initialised.
I added the previous field which is unnecessary in my case, but it shows the parent is linked as expected by using Self as type: so I get access to the parent fields.
For one, s can't be moved[1] while there's a reference to it alive -- the reference would dangle. For two, more generally, you can never take a reference to a local like s for a lifetime that exists outside of the function body like 'a -- s must either move or go out of scope by the end of the fundion body.
Your link-list-esque chain of arbitrarily typed data is suspect too, but I don't know enough about the high-level goal to say much else.
At a minimum, you have some misconceptions about references. They're generally for short-lived borrows and don't, for example, cause the referent to stay alive. (Rust has no builtin garbage collector to make that feasible.)
Maybe Boxes (which are like an owning pointer) and/or type erasure could help, but that's mostly a shot in the dark. Maybe the design generally is a poor fit for Rust.
or otherwise used, since this is an exclusive reference (&mut) âŠī¸
Even with unsafe, &mut aren't the right tool for the job. Creating two &mut to the same place which can be active at the same time is UB. Raw pointers may be a better fit.
Even though it's about homogenous linked lists, you may want to read this book.