input-rust

Crates.ioinput-rust
lib.rsinput-rust
version1.0.1
created_at2024-12-20 11:13:40.626262+00
updated_at2024-12-20 11:35:42.982322+00
descriptionA Rust crate for prompting user input, similar to Python's input(), with error handling.
homepage
repository
max_upload_size
id1490068
size3,302
Saikat Das (dis70rt)

documentation

README

input-rust 🦀

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.

Features

  • Prompts the user for input with a custom message.
  • Returns an error if the input is empty.
  • Provides error handling for input failures.

Installation

Add this to your Cargo.toml file:

[dependencies]
input-rust = "1.0.0"

Usage

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);
}

Error Handling

If the user enters an empty string or an error occurs, the input function will return an error with a descriptive message:

  • If the input is empty, an InvalidInput error is returned.
  • If there is any other error reading the input, it returns an error of type Other.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Commit count: 0

cargo fmt