These are chat archives for rust-lang/rust

7th
Mar 2018
jpathy
@jpathy
Mar 07 2018 03:32
how do i recover the underlying stream for ForEach?
Ghoughpteighbteau
@Ghoughpteighbteau
Mar 07 2018 03:33
the iterator? if you name it I think you can get at it.
jpathy
@jpathy
Mar 07 2018 03:33
sorry it's for futures.
Ghoughpteighbteau
@Ghoughpteighbteau
Mar 07 2018 03:35
futures? async thing? what library you using?
jpathy
@jpathy
Mar 07 2018 03:36
sorry, it's not meant for this channel. i have moved it to tokio-rs
Ghoughpteighbteau
@Ghoughpteighbteau
Mar 07 2018 03:37
lol
Denis Lisov
@tanriol
Mar 07 2018 09:22
@Dylan-DPC Sounds like a case for associated types, no?
Dylan DPC
@Dylan-DPC
Mar 07 2018 09:23
Associated types?
Denis Lisov
@tanriol
Mar 07 2018 09:26
Something like this
Niranjan A Kartha
@n-kartha
Mar 07 2018 12:23
How can I compare between a usize and an isize? Do I have to implement my own PartialOrd?
Wait I'm dumb
I got it, nevermind
Dylan DPC
@Dylan-DPC
Mar 07 2018 12:29
thanks @tanriol. I will try and see if it works well
Ingvar Stepanyan
@RReverser
Mar 07 2018 20:43
@n-kartha Actually that's a good point, I wonder why stdlib doesn't define PartialOrd between (signed, unsigned) pairs
Given that in cases like [ui]64 / [ui]128 / [ui]size / ... you can't easily cast them both to one type for correct comparison
Songbird0
@Songbird0
Mar 07 2018 21:25
@apiraino no problem in my own.
Songbird0
@Songbird0
Mar 07 2018 21:33

Hi!

I'm having some problem with explicit (or implicit) lock on stdin (Rust 1.23, cargo 0.24). Here are my tests:

use std::io::{self, Read};

fn main() {
    println!("Write something:");
    let mut content = String::new();
    let stdin = io::stdin();
    let mut mutex = stdin.lock();
    mutex.read_to_string(&mut content).unwrap();
 // std::mem::drop(mutex) doesn't work
    let content = content;
    println!("Your answer: {}", &content);
}

Standard input isn't unlocked, ever.

The lock is released when the returned lock goes out of scope. - rustdoc

Ok, then I tried this:

use std::io::{self, Read};

fn main() {
    println!("Write something:");
    let mut content = String::new();
    let stdin = io::stdin();
    {
        let mut mutex = stdin.lock();
        mutex.read_to_string(&mut content).unwrap();
    }
    let content = content;
    println!("Your answer: {}", &content);
}

Same problem. Where is my error?

Note: Stdin.read_line() works well, though.

Oh, these tests has been executed into Windows10 cmd.
Denis Lisov
@tanriol
Mar 07 2018 21:41
@Songbird0 Note that read_to_string reads not to the newline, but to the end of input.
Ghoughpteighbteau
@Ghoughpteighbteau
Mar 07 2018 21:42
darn it
I was gonna say
Write something:
asdf
Your answer: asdf
(I hit ctrl+d to issue an EOF to the program)
not sure how to do that on windows 10 cmd tho.
Denis Lisov
@tanriol
Mar 07 2018 21:43
Possibly Ctrl+Z or Enter followed by Ctrl+Z
Songbird0
@Songbird0
Mar 07 2018 21:45
All right. I misread it, again. ^^'
Thanks.
@Ghoughpteighbteau I reproduced that, I've the same result.
Ghoughpteighbteau
@Ghoughpteighbteau
Mar 07 2018 21:46
what a persnickety markdown format.
Songbird0
@Songbird0
Mar 07 2018 21:47
Ahah. That's why I write my message into the editor before posting. :)