9 ms·
Show HN: Rust-starter, a boilerplate to build Rust CLI applications
- kosolam 6y agoNotice: Failure lib is deprecated now
- csomar 6y agoYou can use the newError branch: https://github.com/rust-starter/rust-starter/tree/newError https://github.com/rust-starter/rust-starter/tree/newError See https://rust-starter.github.io/#feature-errors https://rust-starter.github.io/#feature-errors for why Failure is still used.
- kibwen 6y agoIndeed, much of what Failure did well has since been upstreamed into Rust's own std::error::Error type. The modern recommendations for error handling convenience libs are thiserror (for library crates, where you want to define errors) and anyhow (for binary crates, where you just want to consume errors), both of which are from the author of Serde. [EDIT: Also snafu, hello there Shepmaster :P ]
- csomar 6y agoUnfortunately, backtracing is only available in nightly for thiserror and anyhow.
- codetrotter 6y agoNonetheless starting people off with something deprecated is not a good idea imo, and will only serve to making migration harder in the future because more and more people keep using said deprecated thing.
- csomar 6y agoYou can switch to the newError branch. One of the things that I like when building stuff for production is that my code compiles on Stable.
- eat_veggies 6y agoDo people still recommend snafu?
- ibraheemdev 6y agoYes, why wouldn't they?
- eat_veggies 6y agoI was just wondering. I'm new to rust and still getting my bearings. Seems like there's a lot of options for error handling, from doing it yourself with an enum to snafu to thiserror and anyhow or (apparently deprecated) failure
- shepmaster 6y agoYep! Really, most of the error handling libraries just reduce the boilerplate associated with creating your own error types. SNAFU also adds some opinions to the mix. You can see what the libraries do by expanding the procedural macros they use. When you look at the output, it's nothing special that you couldn't have done yourself!
- shepmaster 6y agoI (the author of SNAFU) absolutely recommend it! It works well for libraries and applications and has bells and whistles you might want, such as backtrace captures on stable Rust.
- emddudley 6y agoWhat is the logo?
- mepian 6y agoLooks like a tank of nitrogen.
- crazypython 6y agoAs soon as https://news.ycombinator.com/item?id=25903259 https://news.ycombinator.com/item?id=25903259 was posted, two posts in /new, it helped bring this one, got to the front page: 26. Show HN: Rust-starter, a boilerplate to build Rust CLI applications (github.com/rust-starter) 18 points by csomar 19 minutes ago | flag | hide | past | 6 comments 27. Finland has slashed homelessness; the rest of Europe is failing (economist.com) 30 points by ashergill 19 minutes ago | flag | hide | past | 11 comments 28. The Reasons I’m Joining BIGtoken as CEO (medium.com/crypto-oracle) 3 points by simonebrunozzi 19 minutes ago | flag | hide | past | 1 comment 29. Upvote to encourage more people to visit New Links on Hacker News (ycombinator.com) 164 points by crazypython 21 minutes ago | hide | past | 19 comments
- kosolam 6y agoI would like to see a rust starter template for fully async (http, db, logging, files) web services with pg as the db
- amdolan 6y agoHere is one built with actix-web that I have looked at https://github.com/nemesiscodex/actix-todo https://github.com/nemesiscodex/actix-todo My advice is pick a http server that you want to use and search github for Cargo.lock
- fnord123 6y agoMight be better to turn this into a cookiecutter template: https://github.com/cookiecutter/cookiecutter https://github.com/cookiecutter/cookiecutter
- rsstack 6y agoLet's not mix these two ecosystems.
- Keats 6y agoI've made https://github.com/Keats/kickstart https://github.com/Keats/kickstart which is roughly the same thing (and improved some bits) without the need to install a python package.
- etxm 6y agoThis looks nice. We switched from cookiecutter to yeoman and it’s been nice, but a bit annoying to need node, a custom node package, and a pile of node modules to get the same effect. I’ll give this a try today. I think my team would love having a single binary to generate our boilerplate.
- Waterluvian 6y agoWhat is the target audience for things like this? Are there people who start projects constantly? Or is this more just a catalog?
- etxm 6y agoPretty edge case use case over here, but we used cookiecutter (and now yeoman) internally for developing user-configured extensions to our app. The extensions all have a lot of boilerplate so we use it as a replacement for a PHONY make target for niceties for the extension author like question prompts, enumerated lists for selecting, etc.
- enriquto 6y agoThat you need a "framework" to build simple CLI tools does not seem to speak too well of the language. I know nothing about rust, but isn't there a simple facility for using argc, argv, and the like?
- DougBTX 6y agoYes, that's std::env::args[0], however a higher level wrapper (I prefer structopt[1]) makes it trivial to produce nice usage output etc. [0] https://doc.rust-lang.org/std/env/fn.args.html https://doc.rust-lang.org/std/env/fn.args.html [1] https://github.com/TeXitoi/structopt https://github.com/TeXitoi/structopt
- ibraheemdev 6y agoYou do not "need a framework" to build simple CLI tools in Rust. Most people use a command line argument parser, the most popular being clap [0]. Or you can just use std::env directly. 0: https://github.com/clap-rs/clap https://github.com/clap-rs/clap
- masklinn 6y agoOr you can use getopts if that's your thing (it's also a library so limited gain over clap/structop, probably smaller & faster to compile though) e.g. that's what Brian Cantrill does[0] because they're an old fogey[1] :D [0] https://github.com/joyent/statemap/blob/rust/src/main.rs#L95 https://github.com/joyent/statemap/blob/rust/src/main.rs#L95 [1] https://github.com/joyent/statemap/pull/41 https://github.com/joyent/statemap/pull/41
- bcantrill 6y agoNot only had I entirely forgotten about that, I now use structopt for everything -- so at least this old dog can still learn new tricks? ;)
- nicoburns 6y agoYou definitely don't need a framework. This seems to be aimed at extras like fancy logging, config file management, and CI setup.
- kibwen 6y agoWhile useful as a list of handy libraries, I don't think you need to concern yourself with using such a framework if you want to build a CLI app in Rust. If your intended CLI interface isn't extremely simple, then pick a handy argument parser like clap or structopt (which is built on top of clap). From there add these other libraries only if you feel the need.
- zucker42 6y agoA project like this can still be very useful if only to show newbies which libraries are the canonical ones. I've noticed with Rust their are many libraries which any experience Rust user would know about but which are not obvious to a newbie.
- burntsushi 6y agoBut it doesn't do that either. For example, it uses failure for error handling, which has been deprecated for quite some time. It would be better to just go look at real CLI utilities and see what they do instead of trying to use something like this IMO. This project seems to just be throwing everything against the wall. It's likely you won't need most of it. For example, this template uses twice as many dependencies as ripgrep.
- jokethrowaway 6y agoI disagree that there are "canonical" libraries outside of std. Rust is quite feature rich and perfectly usable without any of these. Some people are a bit trigger happy when adding dependencies, without considering the extra cost in maintenance and security.
- zucker42 6y agoI consider rand, clap, tokio, serde, and hyper, among others, to be canonical Rust libraries. There may be alternatives, but a new person might be wondering "how do I generate a random number in Rust" and not want to roll their own RNG or find another library. And that's not to say you have to use any of those in any particular project, just that they are the main options for achieving their particular functionality.
- yhoiseth 6y agoLooks great! I’ve missed something like this. A couple of questions: 1. Is there an example application that uses the starter? 2. Does it follow the command line interface guidelines at https://clig.dev https://clig.dev?
- csomar 6y ago1. This was just released :) beyond internal apps I'm building, I guess no. But the project itself is already an example application. 2. First time I this. There are things that relate to Clap and things (like configuration) that could be implemented in rust-starter.
- jzelinskie 6y agoIf you haven't seen it, I'll give a shoutout to abscissa[0]. It's used in production by quite a few apps, basically had everything I was looking for, and demonstrated thought towards why dependencies they have chosen and what those dependencies transitively include. [0]: https://github.com/iqlusioninc/abscissa https://github.com/iqlusioninc/abscissa