# Overloading with tuples

**URL:** <https://internals.rust-lang.org/t/overloading-with-tuples/15719>\
**Category:** language design\
**Created:** [December 4, 2021, 10:16pm UTC](https://internals.rust-lang.org/t/overloading-with-tuples/15719 "2021-12-04T22:16:49Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [December 4, 2021, 11:24pm UTC](https://internals.rust-lang.org/t/overloading-with-tuples/15719/2 "2021-12-04T23:24:36Z")

</div>

So what I usually say is that Rust has _principled_ overloading, as opposed to the [_ad-hoc_](http://www.cs.cornell.edu/courses/JavaAndDS/files/PolymorphismAdHoc.pdf) overloading that's common elsewhere. And that's important both for how Rust does generics as well as for how it does type inference.

> [@VorfeedCanal](#):
>
> This may sound like a useless syntax sugar, but can be used to make foreign JavaScript and C++ APIs much easier to use. Because currently used approach provides monstrosities like [init\_mouse\_event\_with\_can\_bubble\_arg\_and\_cancelable\_arg\_and\_view\_arg\_and\_detail\_arg\_and\_screen\_x\_arg\_and\_screen\_y\_arg\_and\_client\_x\_arg\_and\_client\_y\_arg\_and\_ctrl\_key\_arg\_and\_alt\_key\_arg\_and\_shift\_key\_arg\_and\_meta\_key\_arg\_and\_button\_arg\_and\_related\_target\_arg](https://docs.rs/web-sys/0.3.55/web_sys/struct.WheelEvent.html#method.init_mouse_event_with_can_bubble_arg_and_cancelable_arg_and_view_arg_and_detail_arg_and_screen_x_arg_and_screen_y_arg_and_client_x_arg_and_client_y_arg_and_ctrl_key_arg_and_alt_key_arg_and_shift_key_arg_and_meta_key_arg_and_button_arg_and_related_target_arg).

So that could have already been `init_mouse_event((more, ..., here))` with a trait -- as you mention -- but notably it wasn't. Have you investigated _why_ they made that choice? What is it about the super-long-name approach that they liked better? The "two more parens" approach is obviously less caller-typing-impact than the long name, so they must have been optimizing for something else.

I'll note that the example on the MDN page is _not_ something I'd consider good in _any_ language:

```js
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null);

```

(I've never seen a function with six boolean parameters that I like.) And they seem to agree, since the method is deprecated in favor of the much simpler [`MouseEvent` constructor](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent).

That one takes only two parameters, the required type one and an options dictionary. Which could translate into rust excellently, with the call potentially looking something like this:

```rust
MouseEvent::new(
    event_name,
    s! {
        clientX = 100,
        altKey = true,
    })

```

(Using the macro from [Short enum variant syntax in some cases - #9 by scottmcm](https://internals.rust-lang.org/t/short-enum-variant-syntax-in-some-cases/13113/9) until Esteban's struct defaults RFC happens.)

And it looks like, in the mean time, they've made a builder for it [MouseEventInit in web\_sys - Rust](https://docs.rs/web-sys/0.3.55/web_sys/struct.MouseEventInit.html) so it can be ergonomically constructed.

---

_[View the full topic](https://internals.rust-lang.org/t/overloading-with-tuples/15719)._
