[rust-dev] user input
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
Re: [rust-dev] user input
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! 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
Re: [rust-dev] user input
On 08/02/14 23:35, Alex Crichton wrote: I'm curious thought what you think is the heavy/verbose aspects of this? I like common patterns having shortcuts here and there! When reading the original post, it did occur to me that there should probably be a readln() equivalent of println(), if only as a special case to keep very simple programs short, or to help people step up from Hello, World. I was concerned that it might interfere with the ability to create a BufferedReader around stdin, but if BufferedReader is a self-contained object/struct/trait, then I guess it should just work. -- Lee ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev
Re: [rust-dev] How to use dynamic polymorphism with collection
On Sat, Feb 8, 2014 at 6:48 PM, Ashish Myles marci...@gmail.com wrote: On Sat, Feb 8, 2014 at 1:21 PM, Philippe Delrieu philippe.delr...@free.fr wrote: pub trait Base { fn do_base(self); } struct TestBase; impl Base for TestBase{ fn do_base(self){ println!(ici); } } trait GenerciFn{ fn do_genericT: Base(self, base: T); } struct DoGenericFn; impl GenerciFn for DoGenericFn { fn do_genericT: Base(self, base: T){ base.do_base(); } } struct ToTestStr{ vec_gen: ~[~TestBase], } impl ToTestStr{ fn testgencallT: GenerciFn(self, gen: T){ for base in self.vec_gen.iter(){ //let test = base as ~TestBase; gen.do_generic(**base); } } } #[main] fn main() { let base = TestBase; let test = ToTestStr {vec_gen: ~[~base],}; let gen = DoGenericFn; test.testgencall(gen); It took me a few attempts to get the for loop right, but here you go. pub trait Base { fn do_base(self); } struct TestBase; impl Base for TestBase { fn do_base(self) { println!(ici); } } trait GenericFn { fn do_generic(self, base: Base); } struct DoGenericFn; impl GenericFn for DoGenericFn { fn do_generic(self, base: Base) { base.do_base(); } } struct ToTestStr { vec_gen: ~[~Base], } impl ToTestStr { fn testgencallT: GenericFn(self, gen: T){ for ref base in self.vec_gen.iter() { gen.do_generic(**base); } } } #[main] fn main() { let testbase = TestBase; let test = ToTestStr {vec_gen: ~[~testbase as ~Base],}; let gen = DoGenericFn; test.testgencall(gen); } Also, for a little more runtime polymorphism, you could change testgencall's declaration to fn testgencall(self, gen: GenericFn) { ... } ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev
Re: [rust-dev] user input
I believe that reading a string from console should be considered one of the simplest task to perform. Ok i do not pretend a sintax like s1 = input() ala Python but perhaps somehting like string s1 = Console.Readline(); as in C# mode would be sufficient for a basic input control... sure, it's more readable... but actually the thing that puzzles me is that you cannot write something like: let mut s1 = stdin.read_line(); cause the compiler complains (why?)it's a matter of taste, of course. Regards On Sun, Feb 9, 2014 at 12:35 AM, Alex Crichton a...@crichton.co wrote: 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! 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
Re: [rust-dev] user input
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 list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev
Re: [rust-dev] user input
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 mailto: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 mailto: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 mailto:Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev ___ Rust-dev mailing list Rust-dev@mozilla.org mailto: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 list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev
Re: [rust-dev] user input
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
Re: [rust-dev] Rust meetup in Paris @MozSpace - 25 February 2014
I don't want to discourage English speakers so I think we should do it in English and optionally switch to French depending on the audience. I have been to a few hacker meetups in Paris where the language of choice for presentations was English (even though 90% of the attendees were French) and it works well. On Sat, Feb 8, 2014 at 1:32 PM, Axel Viala axel.vi...@darnuria.eu wrote: Hello everybody! (Sorry for my English it's not my mother tongue...) Nical, Pnkfelix and I are organizing a Rust meetup in Paris in the Mozilla space. If you want to come well free to register here however a lot of thing would be in French : https://www.eventbrite.fr/e/billets-rust-paris-meetup-10528169037 Actually we are actually 25/50 peoples. And we are planning to make some talks and workshop(like trying to contribute to the tutorial) etc... Thanks for reading and if you have some questions, don't hesitate to reply :) ___ 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
Re: [rust-dev] user input
On 2/8/14 3:35 PM, Alex Crichton wrote: 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! Is there any way we can get rid of the need to create a buffered reader? It feels too enterprisey. Patrick ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev