💾 Archived View for uscoffings.net › tech › programming › learning-rust.md captured on 2024-06-19 at 22:51:27.
View Raw
More Information
⬅️ Previous capture (2022-06-03)
-=-=-=-=-=-=-
{
"title" : "Learning Rust",
"date" : "2018-02-07",
"tags" : ["rust"]
}
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
- Minimal runtime dependencies. I can build against 3rd-party crates, and the resulting binary
only links against system libraries.
- `cargo doc --open` No cobbled-together Doxygen/CMake/whatever solutions, or recursive grepping
through headers.
# 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:
[profile.release]
lto = true
Release build is not stripped? Takes it to 955KiB.
je\_malloc is large. (But what actually uses it?) You can use libc malloc instead.
#![feature(alloc_system)]
extern crate alloc_system;
Nuke panic:
[profile.release]
panic = 'abort'
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;