pub struct FormInputBuilder { /* private fields */ }

Implementations§

source§

impl FormInputBuilder

source

pub fn new() -> Self

source

pub fn label_field(self, text: &str) -> Self

Form Field: Text output

source

pub fn seperator_field(self) -> Self

Form Field: Vertical spacing

source

pub fn text_field(self, prompt: &str, default: Option<&str>) -> Self

Form Field: Prompt for a string value

source

pub fn multiline_field(self, prompt: &str, default: Option<&str>) -> Self

Form Field: Prompt for multi-line string value

source

pub fn integer_field(self, prompt: &str, default: Option<i64>) -> Self

Form Field: Prompt for an integer

source

pub fn address_field( self, prompt: &str, view: Option<Ref<BinaryView>>, current_address: Option<u64>, default: Option<u64> ) -> Self

Form Field: Prompt for an address

source

pub fn choice_field( self, prompt: &str, choices: &[&str], default: Option<usize> ) -> Self

Form Field: Prompt for a choice from provided options

source

pub fn open_file_field( self, prompt: &str, ext: Option<&str>, default: Option<&str> ) -> Self

Form Field: Prompt for file to open

source

pub fn save_file_field( self, prompt: &str, ext: Option<&str>, default_name: Option<&str>, default: Option<&str> ) -> Self

Form Field: Prompt for file to save to

source

pub fn directory_name_field( self, prompt: &str, default_name: Option<&str>, default: Option<&str> ) -> Self

Form Field: Prompt for directory name

source

pub fn get_form_input(&mut self, title: &str) -> Vec<FormResponses>

Prompts the user for a set of inputs specified in fields with given title. The fields parameter is a list which can contain the following types:

This API is flexible and works both in the UI via a pop-up dialog and on the command-line.

let responses = FormInputBuilder::new()
    .text_field("First Name", None)
    .text_field("Last Name", None)
    .choice_field(
        "Favorite Food",
        &vec![
            "Pizza",
            "Also Pizza",
            "Also Pizza",
            "Yummy Pizza",
            "Wrong Answer",
        ],
        Some(0),
    )
    .get_form_input("Form Title");

let food = match responses[2] {
    FormResponses::Index(0) => "Pizza",
    FormResponses::Index(1) => "Also Pizza",
    FormResponses::Index(2) => "Also Pizza",
    FormResponses::Index(3) => "Wrong Answer",
    _ => panic!("This person doesn't like pizza?!?"),
};

let FormResponses::String(last_name) = &responses[0] else {
   unreachable!()
};
let FormResponses::String(first_name) = &responses[1] else {
   unreachable!()
};

println!("{} {} likes {}", &first_name, &last_name, food);

Trait Implementations§

source§

impl Default for FormInputBuilder

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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>,

§

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>,

§

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.