Learn more about Russian war crimes in Ukraine.

Hello world in Rust

I’m tinkering with Rust. Here’s how I started.

Rust has a classic “pipe curl to shell” installer: curl https://sh.rustup.rs -sSf | sh. The installer works out what platform I’m on. It downloads some stuff and puts it in /Users/jim/.cargo. “Cargo” is Rust’s package manager. It added export PATH="$HOME/.cargo/bin:$PATH" to my ~/.bash_profile, so now I have access to some binaries there, including cargo (the package manager), rustup (a Rust version manager, so you don’t have to run that curl-to-shell installer every time) and rustc, the Rust compiler.

To test rustc, I created hello.rs:

fn main() {
    println!("Hello World!");
$ rustc hello.rs
$ ./hello
Hello World!

We can compare this file to the equivalent in C:

#include <stdio.h>
int main() {
  printf("Hello world!\n");
  return 0;

The Rust binary has an overhead of around 420K. I don’t know what’s in there!

Both binaries depend on /usr/lib/libSystem.B.dylib, the macOS system library. This provides, amongst other things, the C standard library. The Rust binary has one other dependency, /usr/lib/libresolv.9.dylib. This provides a DNS client, includable in C with resolv.h, linkable in C with -lresolv, and documented in man 3 resolver. It’s not clear why the Rust binary depends on this.

What can computers do? What are the limits of mathematics? And just how busy can a busy beaver be? This year, I’m writing Busy Beavers, a unique interactive book on computability theory. You and I will take a practical and modern approach to answering these questions — or at least learning why some questions are unanswerable!

It’s only $19, and you can get 50% off if you find the discount code ... Not quite. Hackers use the console!

After months of secret toil, I and Andrew Carr released Everyday Data Science, a unique interactive online course! You’ll make the perfect glass of lemonade using Thompson sampling. You’ll lose weight with differential equations. And you might just qualify for the Olympics with a bit of statistics!

It’s $29, but you can get 50% off if you find the discount code ... Not quite. Hackers use the console!

More by Jim

Tagged . All content copyright James Fisher 2017. This post is not associated with my employer. Found an error? Edit this page.