Std::mem::sizeof<T>()


#1

I’ve got a structure with C representation:

struct Scard_IO_Request
{
    proto: u32,
    pciLength: u32
}

when I want to ask the sizeof (like in C sizeof()) using:

mem::sizeof<Scard_IO_Request>();

I get compilation error:

“error: sizeof is a reserved keyword”

Why can’t I use this sizeof function like in C? Is there an alternative?


#2

The standard library function is std::mem::size_of (with an underscore before of).


#3

Uhh… https://stackoverflow.com/questions/36664327/using-memsizeof-to-get-size-of-a-user-defined-struct-in-rust


#4

It looks like this was simultaneously posted in both places, but the post here was caught in a spam filter for a day waiting for admin review.


#5

Ah; so what you’re saying is the forum is a nasty little liar when it comes to timestamps? :stuck_out_tongue:


#6

I was very impatient. The stackoverflow solved it.
But thanks anyway.