3 releases

Uses new Rust 2024

new 0.1.7 Apr 21, 2025
0.1.6 Apr 21, 2025
0.1.5 Apr 21, 2025

#291 in Development tools

Download history 234/week @ 2025-04-16

234 downloads per month

MIT license

8KB
149 lines

data-input

Console (or text file) input assistant.

This crate provides a method to help you input data from the console (or text file). You can enter data of any primitive type (numbers, logical or chars), as well as strings. Crate provides the Input trait and its implementations for Stdin and File objects.

Example:

let console = std::io::stdin();

let name = console.import::<String>().unwrap();
let age = console.import::<u32>().unwrap();

println!("Name: {}, age: {}", name, age)

In the given example the variable age will have type u32.

Line feed characters are used as separators for input strings (spaces and tabs are included to string). For other types (not strings) separators are: spaces, tabs and line feeds.

Trailing spaces are removed for all data types.

Example:

Albert Einstein     <-- will be entered as one string value (if import::<String>() use)
1879 1955           <-- will be entered as two numerical values (if import::<u32>() use twice)

Similar syntax for entering data from a text file.

Example:

let f = File::open("example.txt").unwrap();

let name = f.import::<String>().unwrap();
let born = f.import::<u32>().unwrap();

println!("Name: {}, born: {}", name, born)

No runtime deps