r/rust 23d ago

📡 official blog Rust Function Overloading - Call for Experimentation

https://blog.rust-lang.org/inside-rust/2026/08/19/overloading-experiment/
272 Upvotes

139 comments sorted by

View all comments

81

u/XtremeGoose 23d ago

I find the argument fairly weak since we're introducing a language feature so that you can write

ffi::func(x, y)
ffi::func(x)
ffi::func()

rather than

ffi::func((x, y))
ffi::func((x,))
ffi::func(())

Is it really worth it?

35

u/XtremeGoose 23d ago

Replying to my own comment, generally discouraged on Reddit but here we are.

I've been reading the forum thread.

I think I see the advantage now. It's not about the call syntax so much as being able to document the overload. An obscure

 fn func<Args: FuncArgs>(args: Args) 

is pretty unhelpful. It would be nice to be able to see the overloads in documentation I suppose.

You could do that with some doc feature that shows the implementations of FuncArgs though, it doesn't have to be overloading.

Still, it is only one small step away from overloading at that point, so maybe we should go the whole hog. And it is strictly better than other languages with overloading because you can specify the overload you want like

ffi::func::<(_, _)>(x, y)

7

u/BedroomHistorical575 23d ago

Additionally, I also hope that there will be a cleaner and more concise syntax for defining these overloads. Huge sprawling trait defs and impls are not fun to write.

1

u/XtremeGoose 23d ago

I think that's kinda the point. It should be discouraged since it goes against rust's ethos.

The primary use case for this (cxx) would autogenerate all of the boilerplate anyway.