Struct Input

Source
pub struct Input { /* private fields */ }
Expand description

A dialog box with a text input field.

This dialog box displays a text and an input field. It returns the text entered by the user or None if the user cancelled the dialog.

§Example

use dialog::DialogBox;

let name = dialog::Input::new("Please enter your name")
    .title("Name")
    .show()
    .expect("Could not display dialog box");
match name {
    Some(name) => println!("Hello {}!", name),
    None => println!("Hello stranger!"),
};

Implementations§

Source§

impl Input

Source

pub fn new(text: impl Into<String>) -> Input

Creates a new input dialog box with the given text.

Examples found in repository?
examples/input.rs (line 7)
6fn main() -> dialog::Result<()> {
7    let input1 = dialog::Input::new("Please enter something").show()?;
8    let input2 = dialog::Input::new("Please enter something")
9        .title("Input form")
10        .show()?;
11    let input3 = dialog::Input::new("Please enter something with a default")
12        .title("Input form")
13        .default("input")
14        .show()?;
15
16    println!("Input 1: {:?}", input1);
17    println!("Input 2: {:?}", input2);
18    println!("Input 3: {:?}", input3);
19    Ok(())
20}
Source

pub fn title(&mut self, title: impl Into<String>) -> &mut Input

Sets the title of this input box.

This method returns a reference to self to enable chaining.

Examples found in repository?
examples/input.rs (line 9)
6fn main() -> dialog::Result<()> {
7    let input1 = dialog::Input::new("Please enter something").show()?;
8    let input2 = dialog::Input::new("Please enter something")
9        .title("Input form")
10        .show()?;
11    let input3 = dialog::Input::new("Please enter something with a default")
12        .title("Input form")
13        .default("input")
14        .show()?;
15
16    println!("Input 1: {:?}", input1);
17    println!("Input 2: {:?}", input2);
18    println!("Input 3: {:?}", input3);
19    Ok(())
20}
Source

pub fn default(&mut self, default: impl Into<String>) -> &mut Input

Sets the default value of this input box.

This method returns a reference to self to enable chaining.

Examples found in repository?
examples/input.rs (line 13)
6fn main() -> dialog::Result<()> {
7    let input1 = dialog::Input::new("Please enter something").show()?;
8    let input2 = dialog::Input::new("Please enter something")
9        .title("Input form")
10        .show()?;
11    let input3 = dialog::Input::new("Please enter something with a default")
12        .title("Input form")
13        .default("input")
14        .show()?;
15
16    println!("Input 1: {:?}", input1);
17    println!("Input 2: {:?}", input2);
18    println!("Input 3: {:?}", input3);
19    Ok(())
20}

Trait Implementations§

Source§

impl DialogBox for Input

Source§

type Output = Option<String>

The type of the data returned by the dialog box.
Source§

fn show_with<B>(&self, backend: impl AsRef<B>) -> Result<Self::Output>
where B: Backend + ?Sized,

Shows this dialog box using the given backend and returns the output.
Source§

fn show(&self) -> Result<Self::Output>

Shows this dialog box using the default backend and returns the output. Read more

Auto Trait Implementations§

§

impl Freeze for Input

§

impl RefUnwindSafe for Input

§

impl Send for Input

§

impl Sync for Input

§

impl Unpin for Input

§

impl UnwindSafe for Input

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.