Can the new `std::sync::OnceLock` replace `once_cell::sync::OnceCell`?

Or what's the difference?

The once_cell crate uses modules to separate the thread safe and non-thread safe versions, but the types have the same names within those modules. The std versions have different names as well as being in different modules. OnceCell for the non-thread safe version and OnceLock for the thread safe version. This makes the types more consistent with the naming scheme of other types in std.

3 Likes

Or is the difference only naming? Then for new projects I will use the std version.

They aren't perfectly identical API wise, but the fundamental operations should work the same.