These are chat archives for rust-lang/rust

23rd
Sep 2017
unreadable
@unreadable
Sep 23 2017 12:09
Is libc linked to rust via bindings or there's another method?
TatriX
@TatriX
Sep 23 2017 12:45
    let server;
    match matches.opt_str("s") {
        None => {
            print_usage_and_exit(opts);
        }
        Some(s) => server = s,
    };
Can I rewrite this fragmens a a oneliner without "mutating" the binding?
Denis Lisov
@tanriol
Sep 23 2017 12:48
let server = matches.opt_str("s")
    .unwrap_or_else(|| print_usage_and_exit(opts));
TatriX
@TatriX
Sep 23 2017 12:49
But it requires lambda to return a String
Oh, if it's return type is ! then it works fine. Thanks!
TatriX
@TatriX
Sep 23 2017 12:54
How can I set a default value for the getopt?
Denis Lisov
@tanriol
Sep 23 2017 12:55
Do you really want to work with getoptsand not some more advanced option parser?
TatriX
@TatriX
Sep 23 2017 12:56
I just want a working solution for a quick tool. What parser could you suggest?
I can see that clap is popular on crates.io. Probably I'll try it.
Denis Lisov
@tanriol
Sep 23 2017 12:57
For quick tools I mostly use structopt, which is a wrapper on top of clap
TatriX
@TatriX
Sep 23 2017 17:39
    let mut children = vec![];
    for srv in servers {
        children.push(thread::spawn(move || { srv.get_status(verbose); }))
    }
    for child in children {
        let _ = child.join();
    }
If I rewrite this as a .iter().map() then threads spawn in sequence. What am I doing wrong?
Denis Lisov
@tanriol
Sep 23 2017 17:41
Do you collect them between spawning and joining?
TatriX
@TatriX
Sep 23 2017 17:45
    let children: Vec<_> = servers
        .into_iter()
        .map(|srv| thread::spawn(move || { srv.get_status(verbose); }))
        .collect();

    for child in children {
        let _ = child.join();
    }
This works, thanks