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

Cyborus04 opened this issue · comments

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

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!