Function constrained_input

Source
pub fn constrained_input<T, C>(constraint: C) -> Result<T, InputError<T>>
where T: FromStr, C: Constraint<T>,
Expand description

Prompts user input in the terminal with an added type constraint.

§WARNING

Make sure that the constraint provided is of the same type as the one you expect.

§Example

use constrained_inputs::{constrained_input, NumberConstraint};
 
fn main() {
    let constraint = NumberConstraint{
        max: Some(20), 
        min: Some(10),
    };
    let int = constrained_input::<i32, _>(constraint).expect("Input was invalid or out of range");
    println!("Your constrained input integer: {}", int);
}

§Errors

This function returns an InputError if the input is invalid, if a parsing error occurs, or if the input does not meet the specified constraints.