get_user_input

Crates.ioget_user_input
lib.rsget_user_input
version0.1.1
sourcesrc
created_at2021-10-30 08:20:19.662177
updated_at2021-10-30 08:43:22.731883
descriptionGet user input with few line of code
homepage
repositoryhttps://github.com/LeeJiaLe/get_user_input
max_upload_size
id474315
size3,606
Deep Sea Lolicon (LeeJiaLe)

documentation

README

get_user_input

Simple library allow to get user input from console with few line of code,

Example usage:

use get_user_input::{get_input, set_from_input};
fn main() {
  let mut a = 0;
  let mut b = 1.0;
  let mut c = 2;
  let mut d = 3.0;

  print!("Enter value for A ({}):", a);
  //directly set from user input, nothing will set if user input invalid value
  set_from_input!(&mut a);

  //apply message by putting arguments after variable
  set_from_input!(&mut b, "Enter value for B ({}):", b);

  print!("Enter value for C ({}):", c);
  //do something when user input invalid value
  if let Ok(i) = get_input!(i32) {
    c = i;
  } else {
    print!("You MUST input valid vaue for C");
    return;
  }

  print!("Enter value for D ({}):", d);
  //apply message by putting arguments after type
  if let Ok(i) = get_input!(f64) {
    d = i;
  } else {
    print!("You MUST input valid vaue for D");
    return;
  }

  println!("{}", a);
  println!("{}", b);
  println!("{}", c);
  println!("{}", d);
}
Commit count: 3

cargo fmt