I'm working on typescript type engine for the swc project. I faced a hard problem that is specific to rust.
Problematic code is
I need to change the order of evaluation. However, the definition of class C4 requires a definition of C5 and C6, while each definition of C5 and C6 requires a definition of C4. It's the same for C5 and C6.
Also, I need to preserve the evaluation context (e.g. In a method named foo declared in a class named Bar) due to type parameters.
I said rust-specific because if I was using other languages, closure can be the solution I think, but in rust, two closure which mutates the same variable cannot exist.
Since the only code in your post is Typescript, not Rust, it's hard to tell what the actual Rust-related question is. But:
I'm fairly sure this is not true if you bring interior mutability into the picture. Try reading std::cell - Rust to figure out if that's what you want.
If you have some object (here - the class) which can be referenced and mutated from several places, you will always need interior mutability - either the Cell/RefCell for single-threaded case, or Mutex/RwLock for multi-threaded one.
Remember that Rust is not a GC (garbage-collected) language. If you have a struct that has a Rust reference to a second struct, and the second struct gets moved (e.g., by being in a vector that reallocates when its element count changes), then you would have a dangling Rust reference in the first struct. The Rust borrow checker will not permit that, so your program won't compile (unlike other non-GC languages such as C/C++, where your program would compile and then sporadically crash at runtime).
There are a number of approaches to avoid such dangling references, such as use of indices or an arena allocator. Those approaches are memory safe, but require more design work by the programmer.
If instead you meant that you want to have classes that recursively invoke each other, that is not possible in Rust without using box or a similar approach that results in a known size for each class instance.