Make size_of available at compile time


As @chris kindly pointed out on StackOverflow, std::mem::size_of() cannot currently be used as a constant expression. size_of::<T>() appears to be evaluated at runtime, which artificially limits the construct in my opinion.

I went searching for historical background and only managed to dig up a mailing list thread from 2012, which punts the issue as a nice to have.

I’m unsure how to proceed at this point. Would an RFC be the logical next step? Does compile time sizeof jive with Rust philosophy?


This has been proposed as an RFC before, but has been postponed (i.e. to be discussed/implemented after 1.0)


Thanks for the link. I figured it wouldn’t block 1.0 but it’s good to see that compile time sizeof is on the radar.