matklad / once_cell

Rust library for single assignment cells and lazy statics without macros
Apache License 2.0
1.84k stars 110 forks source link

[Feature Request] get_or_maybe_init #162

Closed Person-93 closed 1 year ago

Person-93 commented 2 years ago

I would like the cells to have a function get_or_maybe_init that is just like get_or_try_init except that it uses an Option instead of a Result.

My use case is for parsing a file, and some of the information needed to process the current line might be later in the file. This is not an error, the current line can be processed in the second pass. I think it'd be clearer if I used an Option instead of a Result<T, ()>.

Is this something that you'd want to implement or accept a PR for?

matklad commented 1 year ago

I think the Result<T, ()> is the right general API here. If a specific case would really benefit from option, it can implement a helper function/wrapper type.