Delegation, Performance, and Inlining

Suppose I've got a type TypeA, and a TypeB that includes it. TypeB delegates some methods to TypeA

struct TypeB {
    value: TypeA,

impl TypeB {
    fn do_something(&self, data: &str) -> SomeResult {

What effect does this kind of delegation have on performance? Is the compiler smart enough to inline this kind of thing without being told?

As long as you're running in release, it's transparent. If you want to check stuff like this you can use godbolt.


That's pretty amazing. (godbolt, I mean). Wow.

Thanks for the answer!

1 Like