let in = readln!() ?

macro_rules! readln(
  () => ({
    let mut stdin = ::std::io::BufferedReader::new(::std::io::stdin());
    stdin.read_line().unwrap()
  })
)




On Sat, Feb 8, 2014 at 4:48 PM, Huon Wilson <dbau...@gmail.com> wrote:

>  There is read_line:
> http://static.rust-lang.org/doc/master/std/io/trait.Buffer.html#method.read_line
>
>
>      use std::io::{stdin, BufferedReader};
>
>      fn main() {
>          let mut stdin = BufferedReader::new(stdin());
>          let line = stdin.read_line().unwrap();
>          println!("{}", line);
>      }
>
>
>
> Huon
>
>
> On 09/02/14 11:44, Liigo Zhuang wrote:
>
>
> 2014年2月9日 上午7:35于 "Alex Crichton" <a...@crichton.co>写道:
> >
> > We do indeed want to make common tasks like this fairly lightweight,
> > but we also strive to require that the program handle possible error
> > cases. Currently, the code you have shows well what one would expect
> > when reading a line of input. On today's master, you might be able to
> > shorten it slightly to:
> >
> >     use std::io::{stdin, BufferedReader};
> >
> >     fn main() {
> >         let mut stdin = BufferedReader::new(stdin());
> >         for line in stdin.lines() {
> >             println!("{}", line);
> >         }
> >     }
> >
> > I'm curious thought what you think is the heavy/verbose aspects of
> > this? I like common patterns having shortcuts here and there!
> >
>
> This is not a common pattern for stdin. Programs often need process
> something when user press return key, immediately. So read one line is more
> useful than read multiple lines, at least for stdin. I agree to need
> stdin.readln or read_line.
>
> > On Sat, Feb 8, 2014 at 3:06 PM, Renato Lenzi <rex...@gmail.com> wrote:
> > > I would like to manage user input for example by storing it in a
> string. I
> > > found this solution:
> > >
> > > use std::io::buffered::BufferedReader;
> > > use std::io::stdin;
> > >
> > > fn main()
> > > {
> > >     let mut stdin = BufferedReader::new(stdin());
> > >     let mut s1 = stdin.read_line().unwrap_or(~"nothing");
> > >     print(s1);
> > >  }
> > >
> > > It works but it seems (to me) a bit verbose, heavy... is there a
> cheaper way
> > > to do this simple task?
> > >
> > > Thx.
> > >
> > > _______________________________________________
> > > Rust-dev mailing list
> > > Rust-dev@mozilla.org
> > > https://mail.mozilla.org/listinfo/rust-dev
> > >
> > _______________________________________________
> > Rust-dev mailing list
> > Rust-dev@mozilla.org
> > https://mail.mozilla.org/listinfo/rust-dev
>
>
> _______________________________________________
> Rust-dev mailing 
> listRust-dev@mozilla.orghttps://mail.mozilla.org/listinfo/rust-dev
>
>
>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
>
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to