Note that we've added the dyn keyword, which tells rust to treat this as a trait object and use dynamic dispatch.
This is actually separate from boxing (these examples are just using normal unboxed references), although typically you would use trait objects with boxing as unboxed trait objects are awkward to work with.
See https://godbolt.org/z/PvM3ox for an example of the compilation: we get two versions of f1 specialized for u32 and u64, but just one for f2.
A monomorphized function looks like this:
A dynamic dispatched function looks like: Note that we've added the dyn keyword, which tells rust to treat this as a trait object and use dynamic dispatch.This is actually separate from boxing (these examples are just using normal unboxed references), although typically you would use trait objects with boxing as unboxed trait objects are awkward to work with.
See https://godbolt.org/z/PvM3ox for an example of the compilation: we get two versions of f1 specialized for u32 and u64, but just one for f2.