Generic struct and optimisation for size

Hello,

When using Generic with Struct, the code of this struct is generated for each Type. This Struct implements some functions that do not use directly this Type. To limit the size of the generated code, have I to bring out theses functions outside the Struct ? Or does the compiler manage this ?

It will almost certainly be deduplicated by the linker. (If binary size is what you are trying to optimize)

If you find there is code bloat, do something like

impl<T> MyType<T> {
    fn method(&self) {
        fn debloat(this: &MyType<()>) { ...}

        debloat(self)
    }
}
3 Likes