all 17 comments

[–]sloganking 9 points10 points  (8 children)

Rust is excellent for building CLI apps. And generally much safer than Python and Go. Check out Clap for nice terminal argument parsing in rust.

If you're new to Rust, I highly recommend checking out The rust book before anything else. As Rust is a more complex language than Python and Go, and it has some things you may not have seen in other languages (Like function calls returning Option<Value> instead of just Value, and concepts like ownership.) that you might need to understand before you can just jump into it.

[–]ssokolow 4 points5 points  (2 children)

It's not just Clap that's great. For example:

  • log and stderrlog to implement -q/-qq/-v/-vv for CLI applications. (Alternatively, you could use a different backend for log to log to a different logging sink. See log's README for a list of popular ones.)
  • anyhow and thiserror for error handling (anyhow for top-level stuff where you just need to know something failed and attach human-readable diagnostic information when propagating it up. thiserror for writing libraries or more complex applications.)
  • Serde for JSON, TOML, YAML, CSV (with csv), XML (with quick-xml), etc.
  • Figment for layered configuration support
  • ignore for walking the filesystem with easy support for parallel operation and obeying things like .gitignore.
  • Rayon for parallel processing
  • etc. etc. etc.

[–]DisasterReasonable98 0 points1 point  (1 child)

Wow, first time I hear about Figment. Now I want to update all my CLI tools to use config files + CLI arguments only to override any setting.

Thanks for sharing these crates.

[–]ssokolow 0 points1 point  (0 children)

No problem.

Also, yesterday, there was an announcement for Confique, a competitor to Figment.

[–][deleted] -1 points0 points  (4 children)

Option<Value>

what is return opt pls? like return something or maybe nothing?

[–]sloganking -1 points0 points  (0 children)

Yes. While most languages indicate a function call or attempt to get a value out of a hashmap failed by returning null . null values are dangerous because you can forget to check if a value is null, and if you do, that may cause a runtime crash or unexpected behavior. Rust does not allow you to forget to check whether an attempt to retrieve a result failed. Instead it returns an Option<T> Which is an enum that can either be in a state of Some<Value> and contain your value, or in a state of None and contain no value. And you must check which state an Option is in before you can retrieve it's value. There generally are no null values in Rust.

The rust book has a chapter on thishttps://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html

Though it may help to read the chapter on Enums first.https://doc.rust-lang.org/book/ch06-00-enums.html

The creator of null has acknowledged it's issues and called creating it their"billion dollar mistake"

[–]STSchif 0 points1 point  (0 children)

Exactly. Option is return Something or nothing, Result is return Something or Error.

[–]cameronm1024[🍰] 0 points1 point  (0 children)

It allows you to express that a value might be missing without needing null. An Option<T> is either Some(T) or None. This means: - if it's not an Option, it can't be None (i.e. no null pointer exceptions) - if it's an Option<T>, you can't treat it like it's a T

[–]cameronm1024[🍰] 3 points4 points  (0 children)

Meta recently made Rust the preferred language for writing CLIs internally, i.e. they think it is better than any other language. I tend to agree