Seems like you could either generate the implementation "eagerly" at compile time (possibly with tree shaking to eliminate it automatically if it's not actually referenced anywhere), or you could generate it "lazily" at runtime, which might be useful if you think it's very unlikely but technically possible that the function might ever be called, and you won't know until runtime.
Note that Rust already does dead code elimination at a couple different levels by default, and generic link-time optimization is always an option on top of that, so I assumed you weren't just referring to that.
Note that Rust already does dead code elimination at a couple different levels by default, and generic link-time optimization is always an option on top of that, so I assumed you weren't just referring to that.