These are chat archives for rust-lang/rust

17th
Nov 2016
Nehal Hasnayeen
@Hasnayeen
Nov 17 2016 12:06
how to print Ok() value without Ok ?
David Harvey-Macaulay
@alteous
Nov 17 2016 12:09

@Hasnayeen

println!("{}", option.unwrap());

is the easy way. A safer way might be:

if let Ok(value) = option {
    println!("{}", value);
}
Nehal Hasnayeen
@Hasnayeen
Nov 17 2016 12:12
my code is like this
    for line in r.lines().enumerate() {
        println!("{:?}", line.1);
    }
it prints like this
Ok("Hello world")
David Harvey-Macaulay
@alteous
Nov 17 2016 12:15
@Hasnayeen You can replace the second line with any of the above snippets with option as line
Actually, my previous comment is not quite correct. What are you actually trying to achieve? What is the type of r?
Nehal Hasnayeen
@Hasnayeen
Nov 17 2016 12:18
@Alteous actually your answer is correct, it works. Thanks man
@Alteous what if let do? can you explain?
Sean Kerr
@seankerr
Nov 17 2016 16:13
Is there a cfg setting that gets the endianness of the host? I have 3 different lines where I need to read in a u16 from file. Due to the minimal amount of bytes I'm reading, I'd prefer to not use byteorder as a dependency.
Sean Kerr
@seankerr
Nov 17 2016 16:29
@maciejhirsz Thank you.
Maciej Hirsz
@maciejhirsz
Nov 17 2016 16:52
has anyone experienced any performance regression when switching from try! macro to the ? operator?
Just trying to use the ? for nicer syntax, parser (which is the one piece I have that uses Result extensively) took a 20% hit: https://github.com/ratel-rust/ratel-core/pull/48#issuecomment-261301646
Daniel Collin
@emoon
Nov 17 2016 19:57
@maciejhirsz have you checked the code-gen?
I just started using it myself but the code I work on now isn’t very performance critical so I haven’t noticed
Maciej Hirsz
@maciejhirsz
Nov 17 2016 19:59
if you mean my codegen (the benchmark) - it has no error handling itself so it's not affected
I'll do some micro benchmarks when I've time
Daniel Collin
@emoon
Nov 17 2016 20:00
oh I see
I was thinking of the generated assembly code of try! vs. ?
I would expect it to be identical
LeRoyce Pearson
@Geemili
Nov 17 2016 21:00
I'm having trouble compiling lazy_static 0.2.1 for rust 1.13.0. Compiling panics with this error: https://gist.github.com/Geemili/b3e106ab8d24fcd05c46081e2dc7c4e7
Alexander Irbis
@alexander-irbis
Nov 17 2016 21:17
@Geemili isn't this a nightly? Recent nightlies had this issue
Check with
rustc --version
LeRoyce Pearson
@Geemili
Nov 17 2016 21:22
@alexander-irbis Actually, it just resolved itself. :/ I did check the version though, and it was cargo 1.13.0-nightly and rustc 1.13.0.
Excuse me, cargo 0.13.0-nightly
Okay, now the error is showing up for a different crate
Alexander Irbis
@alexander-irbis
Nov 17 2016 21:37
@Geemili if you use rustup you can try to override compiler version to older
rustup override set 1.12.1