Skip to main content

prompt_rollback

Function prompt_rollback 

Source
pub fn prompt_rollback(backup: &[u8], path: &Path) -> Result<()>
Expand description

Prompt user for action when validation fails: retry, rollback, or abort.

Displays the validation error and presents an interactive prompt with three options:

  • ‘y’ or ‘retry’: Re-open the editor for another attempt (returns Ok)
  • ‘r’ or ‘rollback’: Restore the original file from backup and abort (returns Ok)
  • ‘n’ or any other input: Abort the edit operation (returns Err)

§Arguments

  • backup - The original file content before editing (in bytes)
  • path - Path to the bean file being edited

§Returns

  • Ok(()) if user chooses ‘retry’ (signals caller to re-open editor) or ‘rollback’
  • Err if user chooses ‘n’/‘abort’

§Examples

match prompt_rollback(&backup, &path) {
    Ok(()) => {
        // User chose retry or rollback - check backup file to determine which
        if path matches backup { /* was rollback */ }
        else { /* was retry */ }
    }
    Err(e) => println!("Edit aborted: {}", e),
}