I have the following code and I'd like to make it work somehow.
The only requirements are that the structs A and B should be able to be derived from Serialize and Deserialize (serde). So I can't wrap the fields in something that doesn't implement Serialize or Deserialize.
You can't make self-referential types in safe Rust. The borrow checking model doesn't allow it. What is the actual, high-level problem you're trying to solve? Usually, there's almost always a better solution than self-referential types.