I have two structs. The first struct, Application should have a reference to the second struct, UserInterface. The second struct should in turn contain a reference to the first struct. So, I want to somehow pass &self when instantiating the UserInterface struct on line 8. I want to do this because I need access to Application from inside UserInterface. Here's my code:
pub struct Application<'a> {
pub user_interface: &'a UserInterface<'a>,
}
impl<'a> Application<'a> {
pub fn new() -> Self {
Self {
user_interface: &UserInterface { selected: 0, app: &self }, // pass &self here somehow
all_entries: read()
}
}
}
pub struct UserInterface<'a> {
selected: u8,
app: &'a Application<'a>
}
impl<'a> UserInterface<'a> {
pub fn populate_screen(&self) {
...
}
}
Is it possible to do this? If not, what are my options? What are the alternatives?