Skip to main content

Console

Trait Console 

Source
pub trait Console {
    // Required methods
    fn say(&mut self, line: &str) -> Result<()>;
    fn ask(&mut self, question: &str, default: Option<&str>) -> Result<String>;
    fn ask_secret(&mut self, question: &str) -> Result<String>;
}
Expand description

The terminal, or a scripted stand-in.

Required Methods§

Source

fn say(&mut self, line: &str) -> Result<()>

Print a line.

Source

fn ask(&mut self, question: &str, default: Option<&str>) -> Result<String>

Ask a question and read one line.

default is shown in the prompt and returned when the answer is empty, so pressing Enter accepts it.

Source

fn ask_secret(&mut self, question: &str) -> Result<String>

Ask for a secret and read one line without echoing it.

An empty answer is legitimate and means “skip”, so this cannot signal refusal by returning an error.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<W: Write> Console for Terminal<'_, W>