3 stable releases

1.0.2 Jan 28, 2025

#898 in Rust patterns

Download history 38/week @ 2024-11-06 186/week @ 2025-01-22 166/week @ 2025-01-29 16/week @ 2025-02-05

368 downloads per month

MIT license

4KB

in

A simple Rust crate that provides Python-style input functions through macros.

Installation

Add this to your Cargo.toml:

[dependencies]
in = "1.0.1"

Usage

This crate provides two macros:

  • input!(): Get user input on the same with an optional prompt
  • inputln!(): Same as input!() but user input is taken on the next line

Examples

use in::input;
use in::inputln;

fn main() {
    let a: String = input!();
    // Enter a number: x
    let x = input!("Enter a number: ").parse::<f32>().unwrap();

    // Enter a number:
    // x
    let y = inputln!("Enter a number: ").parse::<f32>().unwrap();
    
    // x
    let z = input!().parse::<f32>().unwrap();

    println!("x = {x}");
}

License

This project is licensed under the MIT License.

No runtime deps