[rust-dev] How to assert or get sizeof(T) at compile time?

James Gao gaozm55 at gmail.com
Fri Dec 28 01:40:29 PST 2012


How can I static_assert(expr) or evaluate sizeof(T) at compile time? Having
these operators/keywords, we can optmize or check many code when compiling.
See the following snippet:

fn dump_memory<T>(t : T) {
  let buff : [u8 * sizeof T] = ....;
  statc_assert (sizeof T < 1024*1024);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20121228/a9f346b0/attachment.html>

More information about the Rust-dev mailing list