In what circumstances should a function be inline?

โš“ Rust    ๐Ÿ“… 2026-01-17    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 2      

surdeus

Hello 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

Read full topic

๐Ÿท๏ธ Rust_feed