Which Option/Result combinator should I use?


There are 27 different methods to convert between Option/Result types and their contained types. Which one should I use?

I ask myself this question a lot, so I made a selection tool for Rust combinators!

You have to input your question like so:

I have in-type and I want out-type by ok-conversion or err-conversion.

For example,

I have Option<T> and I want Option<U> by running a closure turning T into Option<U> or propagating None

You want: Option::and_then

It works well enough right now, but I’m not a UI designer. If anyone with leet CSS/JS skills wants to make it look nicer, I’ll gladly except your PR.


Neat idea! Thanks for sharing it.


There is also a useful Vec<Result<T, E>> -> Result<Vec<T>, E> transformation via collect


Oh, sweet! I’m wondering how to best represent this… I have Iterator<Result<T,E>> and I want Result<Collection<T>,E> by collecting the result and propagating the first error? And then link to Iterator::collect? Samething for Option btw.


Seems a good idea to have a centralized place to aggregate these nice efforts?


I like this! It also makes it clear which corners are missing. Eg, I wanted Result::unwrap_err_or() a few days ago…


http://forge.rust-lang.org is a place intended for things like that.