It looks like you probably hit the unsized type issue, and then tried to work around it by passing a reference instead. Am I right?

I may misunderstand this, but I think the problem is that the lifetime is incoherent, because the outer references can’t outlive the inner ones (because they are created later). The solution here is to box the contained struct, rather than passing a reference. I think you may also need to give A ownership of the contained structs. So something like:

The problem is that you’re requiring all lifetimes to be equal. So b must live as long as a, which it can’t because b is dropped before a at the end of the function.

You could use two lifetimes (with an “outlives” relationship), but since the type is recursive I’m not sure it is possible to express it for arbitrary nesting without needing arbitrary many lifetimes in the type.