Aside from Duration, are there any other `const fn`s in stable?

I was kind of surprised to see const D: Duration = Duration::from_millis(...) actually work on stable. Given that const_fn hasn't been stabilized yet, I figured this wouldn't be possible.

Are there any other instances of const functions in the standard library, available on stable?

There are several in std::mem. A couple others that spring to mind:

  • Cell::new()/RefCell::new()
  • AtomicUsize::new()

I’m sure there are others.

std can use unstable features internally so const_fn being unstable isn’t a blocker for it.

1 Like