top | item 21901072

(no title)

archie2 | 6 years ago

Somebody that knows zilch about Rust with a question: I like to write CLI tools with Go, the built-in libs and the simpleness of the language make it really easy for writing good tools quickly. What advantages does Rust have over Go that one would use it for this purpose?

discuss

order

PrototypeNM1|6 years ago

I don't know the current state of go package management but I do know the equivalent Go project cited Rust's package manager Cargo as a good reference for developing their own. You forget Rust's standard library is quite minimalist and you get to sample competing libraries which often use interchangeable interfaces. In particular there are several crates (libraries) which make handling CLI arguments convenient.

If your code is stateful the typestate pattern is particularly easy to write in Rust - http://cliffle.com/blog/rust-typestate/

archie2|6 years ago

I've never heard of the TypeState Pattern, thanks for the link and it even got me interested in getting to know more about Rust. Thanks a bunch!

iudqnolq|6 years ago

I'm not certain, just learning it. You might find this blog post that does a code review of ripgrep interesting, though. It's a deep dive into a serious-scale cli tool.

https://web.archive.org/web/20190401042439/http://blog.mbrt....

Here's what the main function looks like:

    fn main() {
        match Args::parse().and_then(run) {
            Ok(count) if count == 0 => process::exit(1),
            Ok(_) => process::exit(0),
            Err(err) => {
                eprintln!("{}", err);
                process::exit(1);
            }
        }
    }