matklad / once_cell

Rust library for single assignment cells and lazy statics without macros

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request] get_or_maybe_init

Person-93 opened this issue · comments

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?

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.