Trait Dialog

Source
pub trait Dialog: Sized {
    type Update;
    type Output;

    // Required methods
    fn update_for_event(event: Event) -> Option<Self::Update>;
    fn perform_update(&mut self, update: Self::Update) -> Result<()>;
    fn state(&self) -> DialogState;
    fn output(self) -> Self::Output;
    fn viewport(&self) -> Viewport;
    fn draw(&mut self, frame: &mut Frame<'_>);

    // Provided methods
    fn run(self) -> Result<Self::Output> { ... }
    fn tick(&mut self) -> bool { ... }
    fn tick_rate(&self) -> Duration { ... }
    fn timeout(&self) -> Option<Duration> { ... }
}

Required Associated Types§

Required Methods§

Source

fn update_for_event(event: Event) -> Option<Self::Update>

Source

fn perform_update(&mut self, update: Self::Update) -> Result<()>

Source

fn state(&self) -> DialogState

Source

fn output(self) -> Self::Output

Source

fn viewport(&self) -> Viewport

Source

fn draw(&mut self, frame: &mut Frame<'_>)

Provided Methods§

Source

fn run(self) -> Result<Self::Output>

Examples found in repository?
examples/input.rs (line 8)
5
6
7
8
9
10
fn main() -> anyhow::Result<()> {
    InputDialog::default()
        .with_prompt(Prompt::inline("Enter some text :) "))
        .run()?;
    Ok(())
}
More examples
Hide additional examples
examples/select.rs (line 5)
4
5
6
7
8
fn main() -> anyhow::Result<()> {
    let result = SelectDialog::new(vec!["one".into(), "two".into(), "three".into()]).run()?;
    println!("{}", result.unwrap_or("<none>".into()));
    Ok(())
}
examples/yes_no.rs (line 5)
4
5
6
7
8
9
fn main() -> anyhow::Result<()> {
    let result = YesNoDialog::default().with_message("Yes or no?").run()?;
    let display = if result { "yes" } else { "no" };
    println!("You chose: {display}");
    Ok(())
}
Source

fn tick(&mut self) -> bool

Source

fn tick_rate(&self) -> Duration

Source

fn timeout(&self) -> Option<Duration>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§