How to return state (or part of state) after a program finishes

Hi All,
I’m writing an program where I’m using iced to configure settings, the program usually runs without a GUI but uses iced to provide one when changing settings. I’d therefore like the ability to return data from iced (at the end of the run is fine) as currently my program structure is

  1. Run GUI
  2. When “save” button is pressed save configuration to file and close iced
  3. Load configuration from file

I’d still like to save the data but it’s annoying to save it and then immediately load it back into memory. Is there a way to instead return the state at the end of the program’s run?

Thanks,