in

Crates.ioin
lib.rsin
version1.0.2
created_at2025-01-28 00:41:10.463781+00
updated_at2025-01-28 03:26:56.03156+00
descriptionPython's input() for Rust
homepagehttps://github.com/rtificr/input
repositoryhttps://github.com/rtificr/input
max_upload_size
id1533104
size3,194
Jay Churchill (rtificr)

documentation

https://docs.rs/in

README

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.

Commit count: 3

cargo fmt