3 ms·
Fluent in C and C++ among others, know nothing about Rust. It's mostly easy to follow, but I'm having trouble with notation like `&[u32]` and `&[u32; P]`. Array
by shawn_w 2y ago
Fluent in C and C++ among others, know nothing about Rust. It's mostly easy to follow, but I'm having trouble with notation like `&[u32]` and `&[u32; P]`. Arrays that hold unsigned 32 bit integers? But there's `Vec<u32>` which also seems like an array type? Is it like the difference between C++ primitive arrays and std::vector?
- dwattttt 2y agoFor `&[u32]` and `&[u32; P]`, those are both references to an array of unsigned 32 but integers, however the former is to an array of any size (and carries its size at runtime), whereas the latter is to an array with an explicitly known size at compile time. It's unusual in C, I think you can express it as `int[24] *` (or possibly some other permutation, I'm away from a compiler). Vec<u32> is pretty much like std::vector compared to them, yeah.
- loeg 2y ago`&[u32]` is essentially `std::span<const uint32_t>`. `&[u32; P]` is similarly something like `std::span<const uint32_t, P>`. `[u32; P]` (no `&`) is essentially `std::array<uint32_t, P>`. `Vec<u32>` is essentially `std::vector<uint32_t>`, yes.
- shawn_w 2y agoThanks