Things I miss in Rust

132 points OneWilling1 113 comments

Since most of my previous work was in C++ and C#, I sometimes catch myself missing certain OO features, especially:

  • function overloading
  • inheritance (not even gonna try 😁)

One thing that comes up a lot for me is constructors. I’d love to be able to define multiple new functions with different parameters, something like:

pub fn new(...)
pub fn new(..., extra_property: T)

Right now this usually turns into patterns like new + with_extra_property etc., which work but feel a bit more verbose.

Is there a fundamental reason why function overloading isn’t possible (or desirable) in Rust? Is it mostly a design philosophy or are there technical constraints? And is this something that’s ever been seriously considered for the language, or is it firmly off the table?

Curious to hear how others think about this, especially folks who came from C++/C# as well.

EDIT:
Conclusion: Builders it is.
P.S. Thanks everyone for the insight!