| Crates.io | input-rust |
| lib.rs | input-rust |
| version | 1.0.1 |
| created_at | 2024-12-20 11:13:40.626262+00 |
| updated_at | 2024-12-20 11:35:42.982322+00 |
| description | A Rust crate for prompting user input, similar to Python's input(), with error handling. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1490068 |
| size | 3,302 |
A simple Rust crate that mimics Python's input() function with error handling. It prompts the user for input, trims it, and ensures it's not empty before returning the result.
Add this to your Cargo.toml file:
[dependencies]
input-rust = "1.0.0"
You can use the input function to prompt the user for input:
use input_rust::input;
fn main() {
match input("Please enter some text: ") {
Ok(value) => println!("You entered: {}", value),
Err(e) => println!("Error: {}", e),
}
let text = input("Please enter some text: ").unwrap();
println!("{}", text);
}
If the user enters an empty string or an error occurs, the input function will return an error with a descriptive message:
InvalidInput error is returned.Other.This project is licensed under the MIT License - see the LICENSE file for details.