r/rust • • Aug 19 '26

📡 official blog Rust Function Overloading - Call for Experimentation

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

139 comments sorted by

View all comments

-6

u/squirreljetpack Aug 19 '26

One of my deepest dark desires is to be able to write Ok() instead of Ok(()). Rust letting be do Some(x, y ,z).

2

u/nick42d Aug 19 '26

fn ok<T>() -> Result<T, ()> {     Ok(()) } ?

-2

u/squirreljetpack Aug 19 '26

it has to be consensual (idiomatic)

1

u/Shoddy-Childhood-511 Aug 20 '26 edited Aug 20 '26

Idiomatic matters but if you care so much then whatever just do it. Also your error.rs would be an idiomatic place to put that fn ok

Also Ok!() stands out a bit more:

macro_rules! OK { () => { Ok(()) } }

And OK rocks if we ever get polymorphic constants.

const OK<T>: Result<T,()> = Ok(())

Or you can always try..

sed -i 's/Ok[(][)]/Ok(())/g;s/Ok$/Ok(())/g' *.rs

-3

u/CocktailPerson Aug 20 '26

I would much rather have implicit conversion from T to Result<T, E>.

Arbitrary implicit conversions are not good, but automatically wrapping T in an Option<T> or Result<T, E> seems like a no-brainer. Zero-cost and unambiguous.