Learning Rust

[date: 2018-02-07]

These are some notes I have taken while learning Rust.

https://doc.rust-lang.org/book/second-edition/ch02-00-guessing-game-tutorial.html

rustbyexample.com

You can call `rustc` directly, but you don't want to. Use `crate`.

Things I love

WTF

https://lifthrasiir.github.io/rustlog/why-is-a-rust-executable-large.html

Why is a simple "hello world" binary 3MiB? There's no GC. The linker should be able to throw out tons of shit.

Googling leads to similar questions, but their binaries are a "mere" 600k for v 1.9.0. My v 2.3.0 is 3MiB.

Huge number of exception and panic symbols.

Release changes almost nothing.

Why does the linker pull in all crates? Feels like ar, not linking static libs.

Link time optimization cuts it from 3 to 2 MiB:

Release build is not stripped? Takes it to 955KiB.

je_malloc is large. (But what actually uses it?) You can use libc malloc instead.

Nuke panic:

backtrace uses a lot.

Is libc linked statically? No, I see snprintf, sbrk, ...

speed

Calling `markdown::to_html()` is astoundingly slow.

Vs C++

Is `std::cmp::Ordering` too simplistic? `Less`, `Equal`, `Greater`. How do infinities compare? NaN? C++ wouldn't simplify this away.

Style

What is the preferred style, when returning a value from a function?

value

or

return value;