This is basically linkme::distributed_slice
, as brought up in the Reddit thread.
I am pretty optimistic about the general approach of exposing distributed elements as a &'static [T]
. I think this solves most of the remaining reasons that people want global constructors that are not already expressible in other ways in Rust. In particular this would supersede inventory
as it would be sufficient for implementing all the things currently based on it: typetag
, gflags
, pyo3
etc.
I would like Rust to support this pattern in some form; syntax tbd. Want to write an RFC? Once this exists I think we can continue to not support global constructors / static initialization which are powerful but unsafe and undesirable for many reasons.