Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> monomorphization bloat

Especially because the fix is so easy, it could just be fixed by the compiler on the fly.

If you have a function

  fn a(arg: Into<C>) {
    expensive/extensive operations here
  }

and call it two times

  a(&"test");
  a(10);

The compiler will generate two functions

  fn a_str(arg: &str) {
  /// expensive/extensive operations
  }
  fn a_u16(arg: u16) {
  /// expensive/extensive operations
  }

This can be fixed by just proxying the duplicated call like this

  fn expensive_ops(arg: C) {
  // ...
  }

  fn a_str(arg: &str) {
    let _arg: C = arg.into();
    expensive_ops(_arg);
  }


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: