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

A way to check if a OnceCell is initialized? #96

Closed konsumlamm closed 2 years ago

konsumlamm commented 4 years ago

As far as i can tell, there is currently no is_initialized function for the OnceCells (and transitively the Lazy types). It could trivially be implemented like this (for OnceCell):

pub fn is_initialized(&self) -> bool {
    self.get().is_some()
}

Is there any reason this doesn't exist yet? If not, I could make a PR for it.

matklad commented 4 years ago

There's no "active" reason for this function not existing, but I think self.get().is_some() would probably be more clear anyway.

konsumlamm commented 4 years ago

I think self.get().is_some() would probably be more clear anyway

How so? I think self.is_initialized() clarifies the intent better. Btw, is there a reason get, get_mut and into_inner aren't exposed by Lazy?

matklad commented 2 years ago

Closing: I don't think this pulls its weight (and Lazy::get now exists)