Observable and subscription

Hello, I’d like to use observable to trigger events in the AppState, basically in my program I have an HashMap<String, Hashset> which represent some dependencies (“A” depends on “B”, “C” …) I’d like to maintain a copy in the iced application AppState and I’d like that, when updating the HashMap also the one in the AppState will update (idk if by sending message or something else). How can I do it?

dep.rs

fn process_java_file() {
    // do stuff
    graph.entry(fqcn).or_default().extend(deps); // by adding this also the one in the appState should update

    Ok(())
}

appstate.rs

pub struct AppState {
    project_dependencies: HashMap<String, HashSet<String>>,
    input_value: String
}

impl AppState {

    pub fn view<'a>(&mut self) -> Element<'_, Message> {
        let mut view_struct = Column::new();

        // 1) Top row: input + button
        let mut top_row = Row::new().spacing(5).padding(8);
        top_row = top_row.push(text_input("Enter project path...", &self.input_value).on_input(|s| GetDependency(s)));
        top_row = top_row.push(button("Analyze").on_press(AskDependency));

        view_struct = view_struct.push(top_row);

        // 2) Scrollable list of dependencies
        let deps_column = Column::new().spacing(5).padding(10);

        view_struct = view_struct.push(deps_column);

        view_struct.into()
    }

    pub fn update(&mut self, message: Message) {
        match message {
            GetDependency(s) => {
                println!("{}", s)
            }
            AskDependency => {
                println!("Input value = {}", self.input_value);
            }
            InsertDependency(s, hs) => {
                self.project_dependencies.insert(s, hs);
            }
            _ => {}
        }
    }
}

You can return impl Into<Task<Message>> from AppState::update. See Update in iced::application - Rust and Task in iced - Rust.

For example AppState::update could return Task::perform(process_java_file, |key, value| Message::InsertDependency(key, value))