This is an automated archive made by the Lemmit Bot.

The original was posted on /r/rust by /u/potato-gun on 2026-01-19 23:19:37+00:00.


I had a function that usually takes a float, but sometimes doesn’t. I was passing in Some(float) everywhere and it was annoying.

I recently learned type T implement Into<Option<T>>, so I changed my function to take value: impl Into<Option<f64>>, and now I can pass in floats without using Some() all of the time.

Maybe well known, but very useful.

Edit: people in the comments bring up some good points, this isn’t always (or even often) a good idea. Be careful not to blow up your compile times with generics, or make inferred types impossible. It may be more of a convenience than a good API choice. Interesting tool to have though.