consio

Crates.ioconsio
lib.rsconsio
version0.1.2
sourcesrc
created_at2023-09-29 04:01:55.253586
updated_at2023-09-30 11:33:23.852164
descriptionconsole input
homepagehttps://github.com/KByys/consio.git
repository
max_upload_size
id987009
size18,511
Karl (blueteary)

documentation

README

Input a line and convert it to any type which implement trait FromBuf

Support Type:

(unsigned) integer (binary, octal, decimal, hex)

float, char, String and their Vec<T>

Usage

use consio::input;
fn main() {
    let str = input!(String).unwrap(); // Console input "Hello World!"
    assert_eq!(str.as_str(), "Hello World!");

    let n = input!(i32).unwrap();  // Console input "11"
    assert_eq!(n, 11);

    let hex = input!(i32).unwrap(); // Console input "11h" or "0x11"
    assert_eq!(hex, 17);

    // print something before input
    let _value = input!(print "Input a string: ").unwrap();

    // input with a default value
    let value = input!(default => i32); // Console input any invalid number
    assert_eq!(value, Default::default());
}
Commit count: 0

cargo fmt