Skip to content

New API for easier value reading from stdin #1142

@dFionov

Description

@dFionov

Today reading value from stdin look like:

let a: i32 = stdin.lock().lines().next().unwrap().unwrap().trim().parse().unwrap();

As i think, Rust needs easier way to do this. E. g. like:

let a = stdin.read::<i32>().ok().expect("Write a number!");
let (b, c, d) = stdin.read::<(i32, f64, bool)>.ok().expect("Please, write integer, float and boolean!");

Activity

changed the title [-]New API for easiest value reading from stdin[/-] [+]New API for easier value reading from stdin[/+] on Jun 1, 2015
steveklabnik

steveklabnik commented on Jun 1, 2015

@steveklabnik
Member

https://crates.io/crates/text_io exists already, you may want to check it out.

dFionov

dFionov commented on Jun 1, 2015

@dFionov
Author

Not bad :) Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @steveklabnik@dFionov

        Issue actions

          New API for easier value reading from stdin · Issue #1142 · rust-lang/rfcs