Skip to main content

Confirm

Struct Confirm 

Source
pub struct Confirm<'a> { /* private fields */ }
Expand description

Builder for a yes/no confirmation prompt.

Wraps Terminal::confirm with a chainable configuration API. Call Confirm::ask to display the prompt and block until the user answers.

§Example

use vecli::Confirm;

let confirmed = Confirm::new("Delete file?")
    .default(false)
    .ask();

Implementations§

Source§

impl<'a> Confirm<'a>

Source

pub fn new(prompt: &'a str) -> Self

Creates a new Confirm with the given question text.

Defaults to false when the user presses Enter, with the default indicator visible.

Examples found in repository?
examples/taskr.rs (line 127)
121fn clear(ctx: &CommandContext) {
122    // Demonstrates: Confirm prompt, global flag
123    if ctx.flags.contains_key("verbose") {
124        println!("[verbose] clear called.");
125    }
126
127    let confirmed = Confirm::new("Clear all tasks?").default(false).ask();
128
129    if confirmed {
130        println!("All tasks cleared.");
131    } else {
132        println!("Aborted.");
133    }
134}
Source

pub fn default(self, default: bool) -> Self

Sets the value returned when the user presses Enter with no input.

Examples found in repository?
examples/taskr.rs (line 127)
121fn clear(ctx: &CommandContext) {
122    // Demonstrates: Confirm prompt, global flag
123    if ctx.flags.contains_key("verbose") {
124        println!("[verbose] clear called.");
125    }
126
127    let confirmed = Confirm::new("Clear all tasks?").default(false).ask();
128
129    if confirmed {
130        println!("All tasks cleared.");
131    } else {
132        println!("Aborted.");
133    }
134}
Source

pub fn show_default(self, show: bool) -> Self

Controls whether [Y/n] or [y/N] is appended to the prompt text.

Source

pub fn ask(self) -> bool

Displays the prompt and returns the user’s answer.

Examples found in repository?
examples/taskr.rs (line 127)
121fn clear(ctx: &CommandContext) {
122    // Demonstrates: Confirm prompt, global flag
123    if ctx.flags.contains_key("verbose") {
124        println!("[verbose] clear called.");
125    }
126
127    let confirmed = Confirm::new("Clear all tasks?").default(false).ask();
128
129    if confirmed {
130        println!("All tasks cleared.");
131    } else {
132        println!("Aborted.");
133    }
134}

Auto Trait Implementations§

§

impl<'a> Freeze for Confirm<'a>

§

impl<'a> RefUnwindSafe for Confirm<'a>

§

impl<'a> Send for Confirm<'a>

§

impl<'a> Sync for Confirm<'a>

§

impl<'a> Unpin for Confirm<'a>

§

impl<'a> UnsafeUnpin for Confirm<'a>

§

impl<'a> UnwindSafe for Confirm<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.