matklad / once_cell

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

Feature request: Add OnceCell::try_unwrap() #28

Closed manuthambi closed 5 years ago

manuthambi commented 5 years ago

Add a method which consumes OnceCell and returns the element if it exists. The method signature can be very similar to Arc::try_unwrap().

pub fn try_unwrap(self) -> Result<T, OnceCell<T>>

manuthambi commented 5 years ago

On second thought, there isn't much point in returning an uninitialized OnceCell if the unwrap fails. So the signature could be: pub fn try_unwrap(self) -> Option<T>

matklad commented 5 years ago

sgmt, though, I think the name and signature should be, to map RefCell:

pub fn into_inner(self) -> Option<T>
manuthambi commented 5 years ago

into_inner sounds better, and it is better to be consistent with RefCell.

I haven't contributed to Rust before, but do you want me to send you a pull request?

matklad commented 5 years ago

Sure, that would be awesome! Here's a checklist of things to do: