Skip to main content

OnCancel

Trait OnCancel 

Source
pub trait OnCancel<T> {
    // Required methods
    fn or_cancel(self, message: &str) -> T;
    fn or_cancel_default(self) -> T;
}
Expand description

Extension trait: gracefully end the process when the user cancels a prompt.

or_cancel(msg) prints msg (or the global settings::cancel when omitted) using the framed ■ … style, then exit(0). Any other error is unwrapped — matching how clack’s isCancel flow is usually used.

§Example

use cli_ui::prompt::{text, OnCancel};

let name = text("Your name").run().or_cancel("See you next time.");
println!("hello {name}");

Required Methods§

Source

fn or_cancel(self, message: &str) -> T

Exit cleanly on cancellation with the given message.

Source

fn or_cancel_default(self) -> T

Exit cleanly on cancellation using the global default message from super::settings.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> OnCancel<T> for Result<T>