These are chat archives for rust-lang/rust

26th
Dec 2018
Dirk Van Haerenborgh
@vhdirk
Dec 26 2018 08:58
Hi guys
oeps, wrong gitter. sorry
Ayush Prashar
@ayushprashar
Dec 26 2018 11:57
hey guys
do we have any ORM with a nosqldb support for rust
?
YoungJu Song
@alxest
Dec 26 2018 12:10
Can someone elaborate a bit more on this sentence? Rust needs to know what types will be in the vector at compile time so it knows exactly how much memory on the heap will be needed to store each element. from here.
Denis Lisov
@tanriol
Dec 26 2018 12:16
Objects in a Vec are stored as one array on the heap. They are stored directly in the array, not behind a reference like they would in Java. The compiler needs to know the size of an element to allocate that array.
If you have some specific questions on this, feel free to ask.
YoungJu Song
@alxest
Dec 26 2018 12:34

@tanriol Thanks a lot!
If we have

enum my_enum { x(i32), y(i128) };
let my_vec = vec![ my_enum::x(0), my_enum::x(0) ];

How much space will my_vec take? (ignoring reserved spaces)

Denis Lisov
@tanriol
Dec 26 2018 12:37
The my_vec stack variable will be 3 usize in length (so 24 bytes on 64-bit); the vector on the heap will have 2 elements of 32 bytes each, so 64 bytes.
Sorry, not correct: the vector on the heap can have 24-byte elements too, at least on x86_64.
YoungJu Song
@alxest
Dec 26 2018 12:52
@tanriol I guess you are saying 32 bits :)
Then if we push one my_enum::y(0), the heap will be like:
[ 0 ] [ 0 ] [ 0 0 0 0 ] (where each 0 is 32-bit sized).
Denis Lisov
@tanriol
Dec 26 2018 12:57
No way, I'm saying bytes. The enum has to have enough memory for any variant (so at least 128 bits for i128) plus memory for the discriminant to know the current option. That's at least 17 bytes. However, i128 has to be aligned to 8 bytes (I was wrong to assume 16 here), so the real size of this enum will be 24 bytes.
YoungJu Song
@alxest
Dec 26 2018 12:58
Ah, now I see.
It is now clear. Thanks a lot for your answer, @tanriol !
Sergey Noskov
@Albibek
Dec 26 2018 18:02
Hey, everyone. I have a question. I want some WebAssembly to be run NOT from JS, but from some custom vm, like wasmi. What should I use to make an exportable function inside webassembly module for such a case? Should I still use wasm-bindgen? If no, is there any docs to read more about this or some code I could look into?