Once_cell 0.1.1: a lazy_static on stable Rust without macros

Hi!

I've recently realized that it is already possible to implement lazy_static! (and more!) on stable Rust with a nice API without macros.

So, once_cell was created, which implements a single assignment cell-like type, which you can just use in a static context, without any strings attached.

See the docs for various examples: once_cell - Rust.

4 Likes

Looks interesting. Is there any proof/reasoning/argument that justifies the use of unsafe to show that it introduces no UB?

Is there any proof/reasoning/argument that justifies the use of unsafe to show that it introduces no UB?

There's definitely no formal proof. The informal reasoning is documented in the source code, and I would really appreciate a unsafe code review: Unsafe audit · Issue #1 · matklad/once_cell · GitHub.

The implementation is mostly based on lazycell and lazy_static, which is not as reassuring as it sounds, because both of them had/have soundness holes :slight_smile:

2 Likes