|
|
|
|
|
by demurgos
414 days ago
|
|
> Strictly speaking, Rust doesn't support overloaded functions. Function overloading is when you define the same function but with different arguments, and the language selects the correct one based on the argument type. In this case, it's two different implementations of a trait for two different types. You're right that there is no function overload in this article, just some implicit derefs. I would argue however that Rust has overloaded functions (function resolution based on argument types) due to how it handles trait resolution with implicit inference. Rust may not have syntax sugar to easily define overloads and people generally try to avoid them, but using argument-based dispatch is extremely common. The most famous example is probably `MyType::from(...)`, but any single-method generic trait using the generics for the method arguments is equivalent to function overloading. There are also other techniques. Using nightly features you can get far enough so a consumer can use native function call syntax. Overload on nightly: https://play.rust-lang.org/?version=nightly&mode=debug&editi... Overload on stable: https://play.rust-lang.org/?version=stable&mode=debug&editio... The mechanism and syntax may be different from overloading in C++ or Java, but as a user the result is the same and it causes the same pain points. |
|
That's all I'm saying.
> as a user the result is the same
That's why I said I didn't think the inaccuracy is the worst detail.