flâneur — a map of the web's best reading

Inline In Rust

matklad.github.io · 918 words · saved by 1 readers

There's a lot of tribal knowledge surrounding #[inline] attribute in Rust. I often find myself teaching how it works, so I finally decided to write this down.

There’s a lot of tribal knowledge surrounding #[inline] attribute in Rust. I often find myself teaching how it works, so I finally decided to write this down. Caveat Emptor: this is what I know, not necessarily what is true. Additionally, exact semantics of #[inline] is not set in stone and may change in future Rust versions. Why Inlining Matters? Inlining is an optimizing transformation which replaces a call to a function with its body. To give a trivial example, during compilation the compiler can transform this code: fn f (w: u32 ) -> u32 { inline_me (w, 2 ) } fn inline_me (x: u32 , y: u32

Explore this link on the map →

related reading