# Rust Programming Langauge

- Page: https://shared.btbytes.com/p/rust
- Date: 2020-03-11
- Tags: rust, programming-language

A modern alternative to C and C++ for system programming.

## Why?

- [Why Rust?](http://web.archive.org/web/20160224015912/http://web.archive.org/web/20160224015912/http://www.oreilly.com/programming/free/files/why-rust.pdf),
a mini book by Jim Blandy of Mozilla. [Sep 2015]
- [Rust for Clojurists](https://gist.github.com/oakes/4af1023b6c5162c6f8f0) [updated Sep 2015].
- [A Swift guide to Rust · faq.sa](http://faq.sealedabstract.com/rust/)
- [Oxidation Plan by Mercury SCM](https://www.mercurial-scm.org/wiki/OxidationPlan) gives good reasons to replace Python code with Rust (and not C).
- [Why is Rust difficult?](https://vorner.github.io/difficult.html)
- ([Blanco-Cuaresma and Bolmont 2017](https://doi.org/10.1017/S1743921316013168)) [arXiv](https://arxiv.org/abs/1702.02951)

## How

- [How to Learn Rust in 2024: A Complete Beginner’s Guide to Mastering Rust Programming | The RustRover Blog](https://blog.jetbrains.com/rust/2024/09/20/how-to-learn-rust/)

## Articles / Talks

- [Visualising Rust's type system](http://web.archive.org/web/20150801151350/http://jadpole.github.io/rust/type-system/); [Jul 2015]
- [OMG Iterators](http://cglab.ca/~abeinges/talks/iter/#0) by Alexis Beingessner of Carleton University + Mozilla Research
- [Packet Capturing MySQL with Rust](http://www.agildata.com/packet-capturing-mysql-with-rust/) -- talks about `Spyglass` a network traffic tool aimed at MySQL data packets.
- [Rust Means Never Having to Close a Socket](http://blog.skylight.io/rust-means-never-having-to-close-a-socket/) - good discussion of the borrow checker etc.,
- [What Are Sum, Product, and Pi Types?](http://manishearth.github.io/blog/2017/03/04/what-are-sum-product-and-pi-types/) by Manish.
- [Math with distances in Rust: safety and correctness across units](http://ferrisellis.com/posts/rust-implementing-units-for-types/)
- [Rust for Serious Developers](https://speakerdeck.com/mitsuhiko/rust-for-serious-developers) by Armin Ronacher.
- [Karol Kuczmarski's Blog – Rust as a gateway drug to Haskell](http://xion.io/post/programming/rust-into-haskell.html)
- [Learning systems programming with Rust - Julia Evans](https://jvns.ca/blog/2016/09/11/rustconf-keynote/) Sept 2016.
- [5 Tips for Writing Small CLI Tools in Rust - Pascal’s Scribbles](https://deterministic.space/rust-cli-tips.html)
- [What Elm and Rust Teach us About the Future](https://dev.to/martincerny/what-elm-and-rust-teach-us-about-the-future)
- [Elegant Library APIs in Rust - Pascal’s Scribbles](https://deterministic.space/elegant-apis-in-rust.html)
- [Josef “Jeff” Sipek » Rust Pointers for C Programmers](http://blahg.josefsipek.net/?p=580)
- [21-security-perf.pdf](https://2018.pass-the-salt.org/files/talks/21-security-perf.pdf) by Pierre C, a contributor to Suricata.
- [Learning rust programming](http://web.archive.org/web/20191021212506/https://www.btbytes.com/tweetstorms/AndreaPessino_Rust.html) by [AndreaPessino](https://x.com/AndreaPessino/status/1042120425415700480)
- [From Bash to Rust](http://web.archive.org/web/20180923114704/https://wiredforge.com/blog/misc/getpid/index.html) Sept 2018.
- [ Rust after the honeymoon](http://dtrace.org/blogs/bmc/2020/10/11/rust-after-the-honeymoon/) Oct 2020 by BryanCantrill.
- [Rust Anthology Master List](https://github.com/brson/rust-anthology/blob/master/master-list.md)


## Books

[The Little Book of Rust Books](https://lborb.github.io/book/title-page.html)

### Print books

- [PacktPublishing/Hands-On-Concurrency-with-Rust: Hands-On Concurrency with Rust, published by Packt](https://github.com/PacktPublishing/Hands-On-Concurrency-with-Rust)
- [PacktPublishing/Network-Programming-with-Rust: Network Programming with Rust, published by Packt](https://github.com/PacktPublishing/Network-Programming-with-Rust)

### Online books

- [Introduction - The Rust Performance Book](https://nnethercote.github.io/perf-book/introduction.html)
- [Rust Design Patterns](https://rust-unofficial.github.io/patterns/intro.html)
- [Learn Rust 101 | A guide to aid you in your journey of becoming a Rustacean (Rust developer).](https://rust-lang.guide/) at <https://rust-lang.guide>
- [Effective Rust](https://effective-rust.com/cover.html)
- [Data Engineering With Rust](https://datawithrust.com/)

## Experience reports

- [Packet Capturing MySQL with Rust](http://www.agildata.com/packet-capturing-mysql-with-rust/)
- [From Mordor, with love: Rust: First impressions from a C++ developer](http://templated-thoughts.blogspot.in/2018/03/rust-first-impressions-from-c-developer.html)
- [Falling in love with Rust](http://dtrace.org/blogs/bmc/2018/09/18/falling-in-love-with-rust/) by Bryan Cantrill.
- [From Julia to Rust](https://miguelraz.github.io/blog/juliatorust/index.html) Aug 2024.

## Papers / reports

- [You can't spell trust without rust](https://github.com/Gankro/thesis) -- master's thesis of Alexis Beingessner. [PDF](https://github.com/Gankro/thesis/blob/master/thesis.pdf)

## Videos / Talks

- [into_rust(): screencasts for learning Rust](http://intorust.com/)
- [Rust Camp 2015](http://confreaks.tv/conferences/rustcamp)
- [Zen and the art of convincing your company to use Rust](https://ashleygwilliams.github.io/rustfest-2017/#1)
- [Steve Klabnik on Why Rust](https://www.youtube.com/watch?v=_-fweBvtifA) [Jul 2015]
- [RustCamp 2015](http://confreaks.tv/events/rustcamp2015)
- [Gökberk Yaltıraklı](https://www.youtube.com/channel/UCYWp8CR6tSEeerww35YXcgg) videos about "port scanner in Rust, Dictionary server with Rust".
- [C++Now 2017: Niko Matsakis "Rust: Hack Without Fear!" - YouTube](https://www.youtube.com/watch?v=lO1z-7cuRYI&feature=youtu.be)

## Blogs

- [Llogiq's blog](https://llogiq.github.io/) -- rust "learner's" blog.
- [Three months of Rust](http://scattered-thoughts.net/blog/2015/06/04/three-months-of-rust/); [Jun 2015] --
appears to be a decent blog to read in general.
- [Herman Radtke's blog](http://hermanradtke.com/archive.html)
- [The blog of Martin Wernstål](http://m4rw3r.github.io/)
- [Design is refactoring](http://designisrefactoring.com/2015/10/02/rust-by-trial-and-error/)
- [Burntsushi's blog](http://blog.burntsushi.net/)
- [Ironic blog](http://nercury.github.io/) --  [Explore the ownership system in Rust](http://nercury.github.io/rust/guide/2015/01/19/ownership.html).
- [Sevag H](https://sevagh.github.io/) -- creator of `pq`.
- [Introducing the Rust crash course](https://www.snoyman.com/blog/2018/10/introducing-rust-crash-course) by Snoyman (Haskell/Yesod)
- [Sabrina Jewson](https://sabrinajewson.org/blog/building-this-site); this entry talks about using Rust to build her blog; [src](https://github.com/SabrinaJewson/sabrinajewson.github.io).


## Tutorials

- [Learning Rust](https://quinedot.github.io/rust-learning/) by `quinedot`.
- [rust-learning](https://github.com/ctjhoa/rust-learning)
- [mre/idiomatic-rust: A peer-reviewed collection of articles/talks/repos which teach idiomatic Rust.](https://github.com/mre/idiomatic-rust)
- [Rust Language Cheat Sheet](https://cheats.rs/)
- [Breakdown Notes](http://web.archive.org/web/20190105100122/https://www.breakdown-notes.com/make/load/rust_cs_canvas/true); Jan 2019
- [Rust Quiz](https://dtolnay.github.io/rust-quiz/) ; med-hard.
- [Welcome - 100 Exercises To Learn Rust](https://rust-exercises.com/01_intro/00_welcome), created by the author of [Zero to Production in Rust](https://www.zero2prod.com/).
- [Welcome to Comprehensive Rust 🦀 - Comprehensive Rust 🦀](https://google.github.io/comprehensive-rust/welcome.html)
- [Introduction - Roguelike Tutorial - In Rust](http://bfnightly.bracketproductions.com/rustbook/chapter_0.html)
- [amos - A half-hour to learn Rust](https://fasterthanli.me/blog/2020/a-half-hour-to-learn-rust/)
- [Guaranteeing memory safety in Rust | Air  Mozilla](https://air.mozilla.org/guaranteeing-memory-safety-in-rust/)
- [Notes on Rust by `rbranson`](https://gist.github.com/rbranson/03d88e3733c6ee098a89)
- [Rust: A Type System You Didn't Know You Wanted](http://pnkfelix.github.io/curry-on2015.html#/)
  by Felix Klock of Mozilla. July 2015/ Curry On conf.
- [Arcaders](http://jadpole.github.io/arcaders/arcaders-1-1/) a tutorial series in building a game with Rust.
- [rust-101](https://www.ralfj.de/projects/rust-101/main.html) -- 16 part tutorial.
- [The Rustonomicon](https://doc.rust-lang.org/nightly/nomicon/README.html) -- The Dark Arts of Advanced and Unsafe Rust Programming
- [24 Days of Rust](http://zsiciarz.github.io/24daysofrust/)
- [nrc/r4cppp: Rust for C++ programmers](https://github.com/nrc/r4cppp) -- this is a pretty good collection of articles.
- [Hello, Rust!](https://www.hellorust.com/)  -- This site will collect resources, guides, articles and links around **Rust & WebAssembly**.
- [rochacbruno/py2rs: A quick reference guide for the Pythonista in the process of becoming a Rustacean](https://github.com/rochacbruno/py2rs)
- [A gentle introduction to Rust](https://stevedonovan.github.io/rust-gentle-intro/readme.html) by Steve Donovan.
- [The Periodic Table of Rust Types](http://web.archive.org/web/20140115031735/http://cosmic.mearie.org/2014/01/periodic-table-of-rust-types/)


## Courseware

- [The Adventures of OS](http://web.archive.org/web/20190927171636/http://web.eecs.utk.edu/~smarz1/osblog/); Making a RISC-V Operating System using Rust by Stephen Marz.
- [EECS 3/495: Concurrent Programming in Rust -2017](http://users.eecs.northwestern.edu/~jesse/course/eecs395rust-sp17/); [2016](http://users.eecs.northwestern.edu/~jesse/course/eecs395rust-wi16/).
- [Introduction - The Rust Programming Language](http://web.archive.org/web/20170308160552/http://rust-lang.github.io/book/second-edition) ; the second edition of the Rust book, WIP.
- [CIS 198: Rust Programming](http://cis198-2016s.github.io/); Spring 2016.
- [Rust class on Operating Systems at Virginia University](http://rust-class.org/index.html).
- [CIS 198: Rust Programming](http://cis198-2016s.github.io/) -- Fall 2016 at UPenn.


## Source code to study

- [LukeMathWalker/zero-to-production: Code for "Zero To Production In Rust", a book on API development using Rust.](https://github.com/LukeMathWalker/zero-to-production)

## Links

- [Rust Playground](https://play.rust-lang.org/)
- [Rust rosetta code problems](https://github.com/hoverbear/rust-rosetta)
- [This week in Rust](http://this-week-in-rust.org/)


## Libraries and tools

- [Lib.rs — home for Rust crates](https://lib.rs/) "Index of 97k+ Rust libraries and applications. Fast, lightweight, opinionated, unofficial alternative to crates.io"
- [Blessed.rs](https://blessed.rs/crates) "which crates they ought to use and which crates they ought to trust."
- [BurntSushi/xsv](https://github.com/BurntSushi/xsv) A fast CSV
  toolkit written in Rust. xsv is a command line program for indexing,
  slicing, analyzing, splitting and joining CSV files.
- [rustdoc](https://doc.rust-lang.org/book/documentation.html) and [sliderust](https://github.com/kmcallister/sliderust) to convert [this](http://cglab.ca/~abeinges/talks/iter/index.md) into [this](http://cglab.ca/~abeinges/talks/iter/#0)
- [Multirust](https://github.com/brson/multirust) -- tool for managing
  multiple installations of the Rust toolchain. It replaces the
  standard Rust toolchain with components that dynamically choose
  between alternate implementations based on context.
- [.gdbinit for rust](https://redd.it/3llho1)
- [coio-rs](https://github.com/zonyitoo/coio-rs) -- Coroutine
  scheduling with work-stealing algorithm; Non-blocking I/O;
  Asynchronous computing APIs.
- [Nickel.rs](http://nickel.rs/) -- web application framework for Rust.
- [leptos-rs/leptos: Build fast web applications with Rust.](https://github.com/leptos-rs/leptos)
- [poem-web/poem: A full-featured and easy-to-use web framework with the Rust programming language.](https://github.com/poem-web/poem)

## WASM

- [Seed](https://seed-rs.org/) -- A Rust framework for creating web apps

## Applications

To study code, library usage etc.,

- [mcux/kylyp: A new Forum](http://web.archive.org/web/20170915031807/https://github.com/mcux/kylyp). The project uses rust, rocket, diesel, postgresql, and responsive design to build a new Forum.

Command Line Tools in Rust: See also: [Common \*nix commands written in Rust – gcollazo](http://web.archive.org/web/20200516201640/https://gcollazo.com/common-nix-commands-written-in-rust/)

![](https://files.btbytes.com/images/i.imgur.com/KoMbQiA.png)


[ekzhang/rustpad: Efficient and minimal collaborative code editor, self-hosted, no database required](https://github.com/ekzhang/rustpad) alternative to codepad.



## Editor setup

- [Emacs and Rust](http://bassam.co/emacs/2015/08/24/rust-with-emacs/). The best setup guide for emacs to date. [Aug 2015]
- Visual Studio + Rust's [tasks.json](https://gist.github.com/Mr-Byte/855cae109e8687cc22c3) setup.

## Performance

- [Profiling Rust Applications on Linux](https://llogiq.github.io/2015/07/15/profiling.html) using valgrind, oprofile.

## Memory Management

- [Memory Management in Rust and Swift – Ryan Levick – Medium](https://medium.com/@itchyankles/memory-management-in-rust-and-swift-8ecda3cdf5b7)
- [Custom allocators in Rust](https://nical.github.io/posts/rust-custom-allocators.html) -- "making it possible for different parts of a program to chose their memory allocation strategies."


## Safety-critical programming

[What is Ferrocene?](https://ferrous-systems.com/blog/ferrocene-open-source/)
> Ferrocene is the main Rust compiler - rustc - but quality managed and qualified for use in automotive and industrial environments (currently by ISO 26262 and IEC 61508) by Ferrous Systems. It operates as a downstream to the Rust project, further increasing its testing and quality on specific platforms.

## References and borrowing

- [Rust: The Hard Parts - Part One · naftuli.wtf](https://naftuli.wtf/2019/03/20/rust-the-hard-parts/) -- references and borrowing.


## Lifetimes

- [Rust Lifetimes for the uninitialised](http://asquera.de/blog/2018-01-29/rust-lifetimes-for-the-uninitialised/) by Florian Gilcher.
- [Understanding Rust Lifetimes](https://medium.com/nearprotocol/understanding-rust-lifetimes-e813bcd405fa); Jan 2019.
- [The Power of Lifetimes](http://pling.jondgoodwin.com/post/lifetimes/)
- [common-rust-lifetime-misconceptions  · pretzelhammer/rust-blog](https://github.com/pretzelhammer/rust-blog/blob/master/posts/common-rust-lifetime-misconceptions.md)

## Async / Await

* [Introduction - Async programming in Rust with async-std](https://book.async.rs/)


## Web

- [Introduction · The Rusty Web](https://davidmcneil.gitbooks.io/the-rusty-web/content/)
- [EpicZenGarden](https://s3.amazonaws.com/mozilla-games/ZenGarden/EpicZenGarden.html) webassembly demo by unreal engine.
- [Gotham | A flexible web framework created in Rust](https://gotham.rs/)

## Embedded

- [Discover the world of microcontrollers through Rust!](http://web.archive.org/web/20170223201903/https://japaric.github.io/discovery/); [hn](https://news.ycombinator.com/item?id=15270189)

> This book is an "introductory course" on microcontroller-based "embedded systems" that uses Rust as the teaching language rather than the usual C/C++.


## Comparisons (Rust vs X)

- [Comparing Rust and Java — Llogiq on stuff](https://llogiq.github.io/2016/02/28/java-rust.html)
- [Rust for professionals](https://overexact.com/rust-for-professionals/) -- "... intended for developers that already know another language. In the examples, Rust is compared with TypeScript, JavaScript or Java, sometimes with C++ or Kotlin."
* [How Swift Achieved Dynamic Linking Where Rust Couldn't](https://gankra.github.io/blah/swift-abi/); Nov 2019.

## FFI

- [rustgo: calling Rust from Go with near-zero overhead](https://blog.filippo.io/rustgo/)
- [Calling Rust From Python | bheisler.github.io](https://bheisler.github.io/post/calling-rust-in-python/)
- [The easiest way to speed up Python with Rust](https://pythonspeed.com/articles/easiest-rust-python/); Jul 2023.
```
// rustimport:pyo3
use pyo3::prelude::*;

#[pyfunction]  // ← expose the function to Python
fn fibonacci(number: u64) -> u64 {
...
```

```
import rustimport.import_hook
from rustfib import fibonacci
```

- [Extending C with Rust – 101 – Spejss Blog](http://spejss.com/index.php/2017/12/03/extending-c-with-rust-101/)
- [Making Python 100x faster with less than 100 lines of Rust](https://ohadravid.github.io/posts/2023-03-rusty-python/); Mar 2023. Good example with profiling. Uses pyo3
- [PyO3/maturin: Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as python packages](https://github.com/PyO3/maturin); Apr 2023. Some projects using `maturin` are  ruff, polars, orjson, [watchfiles](https://shared.btbytes.com/p/watchfiles) and a few [apache-arrow](https://shared.btbytes.com/p/apache-arrow) projects.


## Discussions

- [A discussion around "Advanced Rust Programming Book Draft"](https://news.ycombinator.com/item?id=9979234)
- [Yield/async/continuations etc., ](https://github.com/rust-lang/rfcs/issues/388)
- [What does Rust have instead of garbage collector? - SO](http://stackoverflow.com/q/32677420)
- [A decent discussion of Rust vs other PLs](https://www.reddit.com/r/rust/comments/3oamul/benefits_of_rust_compared_to_go_or_haskell/)
  on r/rust [Oct 2015].
- [What has rust borrowed from Haskell](https://redd.it/4jpt7e)
- [rust - How can this instance seemingly outlive its own parameter lifetime? - Stack Overflow](http://stackoverflow.com/questions/42637911/how-can-this-instance-seemingly-outlive-its-own-parameter-lifetime/42639814#42639814)


## Cargo

- [Make your own make](https://matklad.github.io/2018/01/03/make-your-own-make.html) -- using Cargo as  a general purpose task automation solution.

Installing a package that is not on `crates.io`: `cargo install -f --git https://github.com/cjbassi/ytop ytop`

- [Cargo Dist](https://opensource.axo.dev/cargo-dist/book/) _distributes your binaries_. and in combination with [oranda](https://opensource.axo.dev/oranda/) it also generates websites.

## Best Practices / Tips

- [Perfect Rust Packaging](https://internals.rust-lang.org/t/perfecting-rust-packaging/2623)
- [spacejam/elements-of-rust: rust style and philosophy](https://github.com/spacejam/elements-of-rust)


## Hardware / bare metal

- [Rust bare metal on ARM microcontroller](http://antoinealb.net/programming/2015/05/01/rust-on-arm-microcontroller.html)


## Rust vs Python

- [rochacbruno/py2rs: A quick reference guide for the Pythonista in the process of becoming a Rustacean](https://github.com/rochacbruno/py2rs)

## Rust and Python

- [Making Python 100x faster with less than 100 lines of Rust](https://ohadravid.github.io/posts/2023-03-rusty-python/) uses `py-spy` for profiling; uses `maturin` to create the project, and `pyo3` to create the bindings.


## Rust vs Java for rest services

-- [via reddit](https://www.reddit.com/r/rust/comments/8xuv0i/rust_vs_java_for_rest_services/)

> I gave a [talk (video)](https://www.twitch.tv/videos/283019651) today about "Rust for Java programmers" at my local java users group. Part of the talk was comparing the implementation of a minimal rest service in a container for the following 4 approaches:

1. Payara-micro (JEE/JAXRS)
1. Wildfly-swarm (another JEE/JAXRS micro deploy)
1. Javaspark (non JEE "lightweight" framework)
1. Rust-rocket

The comparisons are striking, viewed in the same 1/2/3/4 sequence above:

* Container Image Size: 173MB / 151MB / 104MB / 2MB

* Container Startup Time: 22.2s / 17.6s / 1.6s / 0.6s

* Memory Usage at Startup: 630MB / 401MB / 34MB / 1.6MB

* Memory Usage under Stress: 647MB / 522MB / 74MB / 1.7MB

* CPU usage and throughput show a similar progression as above.

> Nice job, Rocket! (results are unscientific. fight me) -- [Source code](https://github.com/softshellack/okcjug-2018-07)

## Success Stories

* [Rust at OneSignal](https://onesignal.com/blog/rust-at-onesignal/) [via](https://news.ycombinator.com/item?id=20835247)

> We had a similar challenge supporting sending this many notifications at OneSignal, which we solved using Rust. We recently hit a peak of 850 Million notifications per second, and 5 billion notifications per day. Here's a blog post on how we do it. Written back when we were at "only" 2 billion notifications per week: https://onesignal.com/blog/rust-at-onesignal/

----

## Rolling log of things

2017-09-08:

There is a new book -- [Programming  Rust](http://shop.oreilly.com/product/0636920040385.do) by Jim Blandy, and Jason Orendorff. Jim Blandy has also written a concise short book [Why Rust](http://web.archive.org/web/20160224015912/http://web.archive.org/web/20160224015912/http://www.oreilly.com/programming/free/files/why-rust.pdf) [PDF]

[Rust is currently unable to call directly into a C++ library](https://doc.rust-lang.org/book/first-edition/ffi.html); so that way Rust is probably behind D.

* [simple event hooks in Rust](http://mattgathu.github.io/simple-events-hook-rust/)
* [Multithreading in Rust with MPSC (Multi-Producer, Single Consumer) channels](https://blog.softwaremill.com/multithreading-in-rust-with-mpsc-multi-producer-single-consumer-channels-db0fc91ae3fa)
* [A web application completely in Rust – Sascha Grunert – Medium](https://medium.com/@saschagrunert/a-web-application-completely-in-rust-6f6bdb6c4471)
* [Rust + actixweb success story](https://www.reddit.com/r/rust/comments/8xdsx5/rust_actixweb_in_the_on_of_the_biggest_music/) July 2018
* [My RustConf 2018 Closing Keynote](https://kyren.github.io/2018/09/14/rustconf-talk.html) Sept 2018.

>  Rust, by design, makes certain programming patterns more painful than others. This is a GOOD thing! It turns out that, for game development, the patterns that end up being the easiest to deal with in Rust closely mirror the patterns that are easiest for game development in any language.
> Rust highly rewards data-oriented design with simple, understandable ownership semantics, and this is great news because this is a really good fit for game development.

----

See also: [rust2018](https://www.btbytes.com/rust2018)

## References

- Blanco-Cuaresma, Bolmont (2017). [What Can the Programming Language Rust Do for Astrophysics?](https://doi.org/10.1017/S1743921316013168).
