Way to avoid a self-referential struct
⚓ Rust 📅 2026-04-22 👤 surdeus 👁️ 2I am working with a library whose setups is such:
let a = A::new();
let b = B::new(&a);
let c = C::new(&a,&b)
Now as a design decision I want to have the setup of the library away from the main function, but still access the fields till the end of main function.
Two solutions I found for this:
- Self-referential struct with ouroboros
- Wrapping the application with the library by sending the whole "main" to the setup process.
Both of these work, and I favor the first one, but I am wondering if there is a more idiomatic/native way of solving this issue.
5 posts - 3 participants
🏷️ Rust_feed