The function that this is part of returns a result. Is there some nice syntax sugar (probably in the std::option::Option) to get rid of the verbose Some(val) => val? Looking forward to your suggestions!
Edit: actually, I do want to return this match statement.
This is really clean. I am using this now (I have function evaluations, so I thought it would be more efficient to lazily evaluate them):
Self::new(percentage, 0.0, 1.0)
.or_else(|| Self::new(percentage, 0.0, 100.0))
.ok_or_else(|| anyhow!("The percentage must be in the range of the specified minimum and maximum values"))?
The only part I am not sure about is the anyhow macro, as I don't know if the macro is a function call, which means I could also just use .ok_or(anyhow!("")). Anyone know about that?
If you're using anyhow you can use anyhow::Context; on visible scope and replace .ok_or_else(|| anyhow!("..."))? with .context("...")? which virtually is same code.