3 ms·
Isn't something like this blocked on the lack of specialisation?
by andrepd 1y ago
Isn't something like this blocked on the lack of specialisation?
- dwattttt 1y agoI believe the specific advice they're referring to has been stable for a while. You take your generic function & split it into a thin generic wrapper, and a non-generic worker. As an example, say your function takes anything that can be turned into a String. You'd write a generic wrapper that does the ToString step, then change the existing function to just take a String. That way when your function is called, only the thin outer function is monomorphised, and the bulk of the work is a single implementation. It's not _that_ commonly known, as it only becomes a problem for a library that becomes popular.
- estebank 1y agoTo illustrate: fn foo<S: Into<String>>(s: S) { fn inner(s: String) { ... } inner(s.into()) }
- deleted 1y ago[deleted]