FormElement

Struct FormElement 

Source
pub struct FormElement<T: Display, Q: Display> {
    pub name: T,
    pub description: Option<Q>,
}
Expand description

A structure to represent an individual option of a form.

Fields§

§name: T§description: Option<Q>

Implementations§

Source§

impl<T: Display, Q: Display> FormElement<T, Q>

Source

pub fn new(name: T, description: Option<Q>) -> Self

Examples found in repository?
examples/example.rs (lines 6-9)
3fn main() -> std::io::Result<()> {
4    let mut form: Vec<FormElement<_, bool>> = Vec::new();
5    for i in 0..100_usize {
6        form.push(FormElement::new(
7            char::from(65 + (i % 26_usize) as u8),
8            None,
9        ));
10    }
11    println!("{}", FormElement::run(&form)?.name);
12
13    Ok(())
14}
Source

pub fn display(list: &[Self])

Displays a table of choices

Source

pub fn run<'a>(list: &'a [Self]) -> Result<&'a Self>

Runs the form, that is to display it and then check for a valid response from the user.

Examples found in repository?
examples/example.rs (line 11)
3fn main() -> std::io::Result<()> {
4    let mut form: Vec<FormElement<_, bool>> = Vec::new();
5    for i in 0..100_usize {
6        form.push(FormElement::new(
7            char::from(65 + (i % 26_usize) as u8),
8            None,
9        ));
10    }
11    println!("{}", FormElement::run(&form)?.name);
12
13    Ok(())
14}

Auto Trait Implementations§

§

impl<T, Q> Freeze for FormElement<T, Q>
where T: Freeze, Q: Freeze,

§

impl<T, Q> RefUnwindSafe for FormElement<T, Q>

§

impl<T, Q> Send for FormElement<T, Q>
where T: Send, Q: Send,

§

impl<T, Q> Sync for FormElement<T, Q>
where T: Sync, Q: Sync,

§

impl<T, Q> Unpin for FormElement<T, Q>
where T: Unpin, Q: Unpin,

§

impl<T, Q> UnwindSafe for FormElement<T, Q>
where T: UnwindSafe, Q: UnwindSafe,

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.