lazy-init icon indicating copy to clipboard operation
lazy-init copied to clipboard

Provide get_or_create variant that returns a Result

Open bonzini opened this issue 6 years ago • 0 comments

It is somewhat unwieldy to pass a closure that can fail to get_or_create. It would be nice to have a try_get_or_create (or something like that) method on Lazy<T>. The method would take a FnOnce() -> Result<T, E> and return a Result<T, E>. The result is Ok if the transformation has been done or succeeds, and Err if the transformation function returns an Err.

bonzini avatar Apr 15 '20 17:04 bonzini