Learning Rust, week 1
By Kunal MehtaI'm trying to learn Rust this summer. I've found I learn languages the best by just trying to do something in it, figuring out the building blocks as I go along. So I plan on writing/porting different projects to Rust.
This week I set up rustup, installed the stable and nightly toolchains and started getting familiar with cargo/the build system.
I ported my newusers Toolforge tool to Rust. It's a simple web server with a single route that makes an API request, and dumps the output in plaintext.
I picked the rocket framework because it seemed more straightforward and similar to Python's Flask compared to hyper, but it was a bit weird to me that it required a nightly build of Rust to compile and run (though it's apparently about to change). I also used Magnus's mediawiki crate mostly to see what it was like, this API request was so simple I didn't really need any MediaWiki-specific code. Thank you to qedk in #wikimedia-tech who helped work around a dependency issue I ran into.
I also wrote up an analysis of supporting Rust tools on Toolforge in the future.
Code written:
- newusers Toolforge tool (~40 lines)
Libraries used:
Concepts learned:
Resultand.unwrap()and.expect(). Still figuring out the?one.- Going from
Vecto an iterator and back to aVecvia.iter()and.collect().
Next week:
- Writing a command-line tool.