logoalt Hacker News

estebank • today at 8:21 PM • 0 replies • view on HN

The "hint" you could provide today for polymorphization is to write code like

    fn needs_string_like(x: Into<String>) {
        fn actual_logic(_: String) {}
        actual_logic(x.into())
    }
which is the explicit way of representing the same thing rustc would be doing automatically. The above will create an almost empty `needs_string_like` for each type that it is called with, but a single `actual_logic`. IIRC some optimization passess would completely remove specific instances of `needs_string_like` (like if you call `needs_string_like(String::new())`).