Yeah, I had similar thoughts around putting an auto-buffered stdin in TLS. I 
think it's a good idea if for no other reason than first impressions.

Patrick

Alex Crichton <[email protected]> wrote:
>> Is there any way we can get rid of the need to create a buffered
>reader? It feels too enterprisey.
>
>There's really no way to efficiently define a `read_line` method on a
>reader that doesn't have an underlying buffer. For that reason, I
>think that we'll always require that the stream be buffered somehow.
>
>Despite that, we could return a buffered stdin by default. We could
>also have task-local stdin handles which hide the ability to be
>buffered. This will not play nicely at all with multiple tasks reading
>stdin, but I don't think the current solution plays very nicely so I'd
>be fine glossing over that use case.
>
>> Ah, that's interesting. In most languages whenever you ask for user
>input (read on stdin) it automatically triggers a flush on stdout and
>stderr
>
>That's a good point that I hadn't thought of. If we go towards a
>task-local stdin then we could make the read methods on the local
>stdin handle flush the local output handles, which would probably
>solve this problem.
>
>
>On Sun, Feb 9, 2014 at 3:26 AM, Matthieu Monrocq
><[email protected]> wrote:
>>
>>
>>
>> On Sun, Feb 9, 2014 at 12:15 PM, Renato Lenzi <[email protected]>
>wrote:
>>>
>>>
>>>
>>> Always talking about read & write i noticed another interesting
>thing:
>>>
>>> use std::io::buffered::BufferedReader;
>>> use std::io::stdin;
>>>
>>> fn main()
>>> {
>>>     print!("Insert your name: ");
>>>     let mut stdin = BufferedReader::new(stdin());
>>>     let s1 = stdin.read_line().unwrap_or(~"nothing");
>>>     print!("Welcome, {}", s1);
>>> }
>>>
>>> when i run this simple code the output "Insert your name" doesn't
>appear
>>> on the screen... only after typing and entering a string the whole
>output
>>> jumps out... am i missing some "flush" (ala Fantom) or similar? I am
>using
>>> Rust 0.9 on W7.
>>
>>
>> Ah, that's interesting. In most languages whenever you ask for user
>input
>> (read on stdin) it automatically triggers a flush on stdout and
>stderr to
>> avoid this uncomfortable situation.
>>
>> I suppose it would not be took difficult to incorporate this in Rust.
>>
>> -- Matthieu.
>>
>>>
>>>
>>>
>>> On Sun, Feb 9, 2014 at 2:40 AM, Patrick Walton
><[email protected]>
>>> wrote:
>>>>
>>>> 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
>>>> [email protected]
>>>> https://mail.mozilla.org/listinfo/rust-dev
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> Rust-dev mailing list
>>> [email protected]
>>> https://mail.mozilla.org/listinfo/rust-dev
>>>
>>
>>
>> _______________________________________________
>> Rust-dev mailing list
>> [email protected]
>> https://mail.mozilla.org/listinfo/rust-dev
>>
>_______________________________________________
>Rust-dev mailing list
>[email protected]
>https://mail.mozilla.org/listinfo/rust-dev

-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to