ExitHandler

Trait ExitHandler 

Source
pub trait ExitHandler: Send + 'static {
    // Provided method
    fn on_exit(&mut self) -> bool { ... }
}
Expand description

Optional hook for agent cleanup on exit.

Implement this trait to run cleanup code before the application exits. This is useful for saving session state, closing connections, or other cleanup tasks.

§Example

struct SaveOnExitHandler {
    session_file: PathBuf,
}

impl ExitHandler for SaveOnExitHandler {
    fn on_exit(&mut self) -> bool {
        // Save session state
        self.save_session();
        true // proceed with exit
    }
}

Provided Methods§

Source

fn on_exit(&mut self) -> bool

Called when exit is confirmed.

Return true to proceed with exit, or false to cancel the exit. This allows handlers to veto the exit if needed (e.g., unsaved changes).

Implementors§