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: `OnceCell::with_value` #164

Closed Cyborus04 closed 2 years ago

Cyborus04 commented 2 years ago

Creates a OnceCell that is already initialized with the provided value, like

let x = OnceCell::new();
let _ = x.set(/* stuff */);

I have a use case where there's two paths to creating the OnceCell, one where the contents are already known, and one where they're calculated later

I could probably implement this, if that's cool

matklad commented 2 years ago

This is already available as a From impl: https://docs.rs/once_cell/1.8.0/src/once_cell/lib.rs.html#800-806

Might be useful to mention it explicitly somewhere in the docs!