In what circumstances should a function be inline?
โ Rust ๐ 2026-01-17 ๐ค surdeus ๐๏ธ 2Hello Rustaceans,please forgive my poor English. I want to ask: under what circumstances should inline be used? My humble opinion is that it makes sense when a function is called very frequently or when the functionโs logic is very small (this can reduce the overhead and number of function calls).
Following this idea, when I was reading core/slice/rotate.rs, I noticed this function:
// FIXME(const-hack): Use cmp::min when available in const
const fn const_min(left: usize, right: usize) -> usize {
if right < left { right } else { left }
}
It is called many times and is very small, but why isnโt it marked as inline?
5 posts - 4 participants
๐ท๏ธ Rust_feed