data-input 0.1.6

Console (or text file) input assistant
Documentation
  • Coverage
  • 33.33%
    1 out of 3 items documented0 out of 2 items with examples
  • Size
  • Source code size: 8.57 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 210.62 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • dvshapkin

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)